Using JNDI to make EJB Find MySQL DataBase
Hello, I'm new to EJB, and I'm trying to develop a Entity EJB which will retrieve data from a simple MySQL table. Though I'm getting this exception: javax.naming.NoInitialContextException
scale is the name of my DB.
try {
initialContext = new InitialContext();
Object homeObject = initialContext.lookup( "java:comp/env/jdbc/scale" );
exemploHome = ( EntityExemploHome )PortableRemoteObject.narrow( homeObject, EntityExemploHome.class );
}catch(NamingException namingException){
namingException.printStackTrace( System.err );
}I dont figure how this simple String should make the EJB find my database, i dont know if I deployed wrong (Used the deploytool). Further the code od the EJB Impl Class:
import java.sql.*;
import java.rmi.RemoteException;
import javax.ejb.*;
import javax.sql.*;
import javax.naming.*;
public class EntityExemploEJB implements EntityBean{
private EntityContext entityCont;
private Connection con;
private Integer condCNPJ;
private String condNome;
public Integer getCondCNPJ(){
return condCNPJ;
public void setCondNome( String nome ){
condNome = nome;
public String getCondNome(){
return condNome;
public Integer ejbCreate( Integer primaryKey )throws CreateException{
condCNPJ = primaryKey;
// INSERT
try {
Statement statement = con.createStatement();
String insert = "INSERT INTO Condominio (condCNPJ) VALUES ("+condCNPJ.intValue()+")";
statement.executeUpdate(insert);
return condCNPJ;
}catch ( SQLException sqlException ) {
throw new CreateException( sqlException.getMessage());
}//FIM ejbCreate
public void ejbPostCreate( Integer primaryKey ) {}
public void ejbStore() throws EJBException{// UPDATE
try {
Integer primaryKey = (Integer)entityCont.getPrimaryKey();
Statement statement = con.createStatement();
// create UPDATE statement
String update = "UPDATE Condominio SET condNome WHERE condCNPJ = "+primaryKey.intValue();
statement.executeUpdate(update);
}catch(SQLException sqlException){
throw new EJBException( sqlException );
}//FIM ejbStore
public void ejbLoad() throws EJBException{
try {
Integer primaryKey = (Integer) entityCont.getPrimaryKey();
Statement statement = con.createStatement();
String select = "SELECT * FROM Condominio WHERE condCNPJ = "+primaryKey.intValue();
ResultSet resultSet = statement.executeQuery(select);
if (resultSet.next()) {
condCNPJ = new Integer( resultSet.getInt( "condCNPJ" ));
condNome = resultSet.getString("condNome");
}else
throw new EJBException( "No such employee." );
}catch ( SQLException sqlException ) {
throw new EJBException( sqlException );
}//FIM ejbLoad
public Integer ejbFindByPrimaryKey(Integer primaryKey)throws FinderException, EJBException {
try {
Statement statement = con.createStatement();
String select = "SELECT condCNPJ FROM Condominio WHERE condCNPJ = "+primaryKey.intValue();
ResultSet resultSet = statement.executeQuery(select);
if(resultSet.next()){
resultSet.close();
statement.close();
return primaryKey;
}//throw ObjectNotFoundException if SELECT produces no records
else
throw new ObjectNotFoundException();
}catch ( SQLException sqlException ) {
throw new EJBException( sqlException );
}//FIM ejbFindByPrimaryKey
public void setEntityContext( EntityContext context )throws EJBException{
// set entityContext
entityCont = context;
try {
InitialContext initialContext = new InitialContext();
// get DataSource reference from JNDI directory
DataSource dataSource = ( DataSource ) initialContext.lookup( "java:comp/env/jdbc/escala" );
// get Connection from DataSource
con = dataSource.getConnection();
}catch ( NamingException namingException ) {
throw new EJBException( namingException );
}catch ( SQLException sqlException ) {
throw new EJBException( sqlException );
}//FIM setEntityContext
public void unsetEntityContext() throws EJBException{
entityCont = null;
// close DataSource Connection
try {
con.close();
}catch( SQLException sqlException ) {
throw new EJBException( sqlException );
}finally {
con = null;
}//FIM unsetEntityContext
public void ejbPassivate(){
condCNPJ = null;
// get primary key value when container activates EJB
public void ejbActivate(){
condCNPJ = ( Integer ) entityCont.getPrimaryKey();
public void ejbRemove() throws RemoveException{}
}//Fecha o EJB
Hi,
Which server r u using? I think u have not included the server jar file in u r classpath. for weblogic server, the look up should be like this.
Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
p.put(Context.PROVIDER_URL,"t3://localhost:7001");
InitialContext ctx = new InitialContext(p);
Object obj = ctx.lookup("HelloBean");
regards
jogesh
Similar Messages
-
How to use Ago function in BIEE with mysql database
Hi experts,
Ago function works well in Oracle database,but when I tried a mysql database,it didn't show results as expected. Anyone knows how to use Ago with mysql as data source?Hi Gurus, need help
-
Calling BRM from UDF using JNDI lookup with @EJB annotation
Hi Experts
I am trying to implement a UDF to invoke my BRM Rules set via JNDI Lookup instead of a SOAP Channel lookup.
I have had a look at the following links/docs:
Calling BRM from UDF using Public API
http://www.gleanster.com/system/resources/W1siZiIsIjIwMTIvMDgvMDcvMjAvNDcvNTAvNDMvVGhpbmdzX1lvdV9TaG91bGRfS25vd19hYm91dF9TQVBfTmV0V2VhdmVyX0JSTS5wZGYiXV0/Things%20You%20Should%20Know%20about%20SAP%20NetWeaver%20BRM.pdf
For item 1 above, the example looks really good, but it doesnt explain how I get access to the following required imports from my UDF:
import com.sap.brms.qrules.ejb.*;
import com.sap.brms.qrules.engine.AbstractProject;
import com.sap.brms.qrules.engine.RuleEngine;
import com.sap.brms.qrules.engine.RulesetContext;
import javax.ejb.EJB;
The second document is really good as well, but I could not figure out how to get it to work from my UDF.
So, can anyone help me to understand specifically what is required to get this to work?
Is is possible to invoke the rule set from my UDF?
How do I give my UDF access to all the required jars/imports?
I have manage to create a new DC (Development Component) with a public part and this enables me to get my code to compile on my local PC but I am not able to activate it due to the server not having access to the same java packages as my local copy.
Any help would be greatly appreciated.You resolve the dependency by importing the required jars with using the dependency tab for the mapping program.
As stipulated before, I have managed to resolve the dependency issue but I have now getting the same error as in the forum: Calling BRM from UDF using Public API
The specific error is:
com.sap.engine.services.cross.PortableRemoteObjectContainer.narrow(PortableRemoteObjectContainer.java:238)
Has anyome manage to get invoke a BRM Ruleset using JNDI? -
Using JSP to write data to MySql database
Please help. I am trying to develop a website where a user registers by filling details required onto a page this data is then posted onto another page and displayed to user the user can the store this data into the database if they are satisfied with it. The problem is although this data is displayed on the next JSP page when I click on save the data is not written to my database.
Code below the problem is with datasave.jsp
Register.jsp:
<html>
<body bgcolor="#d0d0d0">
<style type ="text/css">
@import "style.css"; </style>
<head>
<script src="form_functions.js" type="text/javascript"></script>
<script type="text/javascript">
function validateForm()
errorMessage = "The following field(s) require your attention:";
hasErrors = false;
newline = "\n - ";
if( isInvalidEmail( form1.email.value ) )
errorMessage += newline + "Email :: must contain a valid email address";
hasErrors = true;
if( isEmpty( form1.Firstname.value ) )
errorMessage += newline + "Firstname :: must not be empty";
hasErrors = true;
if( isEmpty( form1.Lastname.value ) )
errorMessage += newline + "Lastname :: must not be empty";
hasErrors = true;
if( isNotInteger( form1.phone.value ) )
errorMessage += newline + "Phone :: must consist of numbers";
hasErrors = true;
if( isEmpty( form1.Address.value ) )
errorMessage += newline + "Address :: must not be empty";
hasErrors = true;
if( isEmpty( form1.City.value ) )
errorMessage += newline + "City :: must not be empty";
hasErrors = true;
if (!document.form1.accept[1].checked)
errorMessage += newline + "Please accept condition to continue";
hasErrors = true;
if( hasErrors )
alert( errorMessage );
return false;
else
return true;
</script>
</head>
<body>
<p>
<body>
<script src="dateLastUpdated.js"
type="text/javascript">
</script>
<p><h1>REGISTER YOUR DETAILS FOR YOUR BUYANDSELL ACCOUNT</h1></p>
<!-- ************* start of form **************** -->
<form
name="form1"
method="POST"
action="datasave.jsp"
onSubmit="return validateForm();"
>
<p>
Email:
<input type="text" name="email"/>
</p>
<p>
Password:
<input type="password" name="Password"/>
</p>
<p>
Firstname:
<input type="text" name="Firstname"/>
</p>
<p>
LastName:
<input type="text" name="Lastname"/>
</p>
<p>
Phone:
<input type="text" name="phone"/>
</p>
<p>
Address:
<input type="text" name="Address"/>
</p>
<p>
City:
<input type="text" name="City"/>
</p>
<p>
Country:
<select name="country">
<option value="Eire">Republic of Ireland </option>
<option value="Northern Ireland">Northern Ireland </option>
</select>
</p>
<p>
Terms and Conditions:
If you accept the Terms and Conditions - please click on "I accept" at the end of this
document.
1. GENERAL
This website is owned and operated by B&S Limited, trading as BuyandSell ("BuyandSell")
whose head office is at BuyandSell House, Argyle Square, Donnybrook, Dublin 4. For the
purpose of these terms and conditions "we", "our" and "us" refers to BuyandSell.
<input type=radio checked name="accept" value="0"> I do not accept<br>
<input type=radio name="accept" value="1">I have read and I accept the Terms and
Conditions
</P>
<p>
<input type="submit" value="Contact Details"/>
</p>
</form>
<!-- ************* end of form **************** -->
<centre>
<script language="JavaScript1.3">
// run script
dateLastUpdated();
</script>
</body> </html>
datasave.jsp:
<html>
<style type ="text/css">
@import "style.css"; </style>
<HEAD>
</script>
</HEAD>
<p><h1>CREATE YOUR BUYANDSELL USER ACCOUNT</h1></p>
</P class= "links">
<body>
<%-- Set the scripting language to Java and --%>
<%-- Import the java.sql package --%>
<%@ page language="java" import="java.sql.*"%>
<%-- -------- Open Connection Code -------- --%>
<%
/* Note: MySQL is accessed through port 3306. NAIJA is the name of the database */
String connectionURL = "jdbc:mysql://localhost:3306/buyandsell";
Connection connection = null;
Statement statement = null;
ResultSet rs = null;
try {
// Load SQL Server class file
Class.forName("com.mysql.jdbc.Driver").newInstance();
// Make a connection to the Mysql
connection = DriverManager.getConnection(connectionURL, "root", "");
%>
<%-- -------- INSERT Code -------- --%>
<%
String action = request.getParameter("action");
// Check if an insertion is requested
if (action != null && action.equals("insert")) {
// Begin transaction
connection.setAutoCommit(false);
// Create the prepared statement and use it to
// INSERT the registration attributes INTO the registration table.
PreparedStatement pstmt = connection.prepareStatement( "INSERT INTO registration(email,Password,Firstname,Lastname,phone,Address,City,Country) VALUES(?,?,?,?,?,?,?,?)");
pstmt.setString(1, request.getParameter("email"));
pstmt.setString(2, request.getParameter("Password"));
pstmt.setString(3, request.getParameter("Firstname"));
pstmt.setString(4, request.getParameter("Lastname"));
pstmt.setDouble(
5, Double.parseDouble(request.getParameter("phone")));
pstmt.setString(6, request.getParameter("Address"));
pstmt.setString(7, request.getParameter("City"));
pstmt.setString(
8, request.getParameter("Country"));
int rowCount = pstmt.executeUpdate();
// Commit transaction
connection.commit();
connection.setAutoCommit(true);
%>
<p>
<p>
<form
NAME="data"
action="Login.html" method="post">
<input type="hidden" value="insert" name="action">
</p>
Email:
<strong>
<%= email %>
</strong>
<p>
Firstname:
<strong>
<%= Firstname %>
</strong>
</p>
<p>
Lastname:
<strong>
<%= Lastname %>
</strong>
</p>
<p>
Phone no:
<strong>
"<%= phone %>"
</strong>
</p>
<p>
Address:
<strong>
<%= Address %>
</strong>
</p>
<p>
City:
<strong>
<%= City %>
</strong>
</p>
<p>
Country:
<strong>
<%= Country %>
</strong>
</p>
<p>
<input type="submit" value="SAVE">
</form>
</p>
<%-- -------- Close Connection Code -------- --%>
<%
// Close the ResultSet
rs.close();
// Close the Statement
statement.close();
// Close the Connection
connection.close();
} catch (SQLException sqle) {
out.println(sqle.getMessage());
} catch (Exception e) {
out.println(e.getMessage());
%>
</body>
</html>Hi,
I think in place of buyandsell put NAIJA
String connectionURL = "jdbc:mysql://localhost:3306/NAIJA "; -
How to use OEM grid control to find any database not in archivelog mode?
Hello,
currently we have 130 databases, say, if I want to pick out any database currently NOT in archivelog mode, is there a quick way to find out ?
by using OEM grid control
or
some trick similar,
but really don't need to check each database manually.
thank you very much!This query works in 12c - please run as SYSMAN.
It is based on undocumented assumptions though +( AND key_value = 'NOARCHIVELOG')+.
SELECT *
FROM SYSMAN.MGMT$GROUP_DERIVED_MEMBERSHIPS O ,
SYSMAN.MGMT$TARGET T ,
sysman.MGMT$AVAILABILITY_CURRENT st
WHERE
o.member_target_type IN ('oracle_database', 'rac_database')
AND ( t.target_type ='rac_database'
OR (t.target_type ='oracle_database'
AND t.type_qualifier3 != 'RACINST'))
AND o. member_target_guid = t.target_guid
AND t.target_guid = st.target_guid
AND st.availability_status = 'Target Up'
AND ( EXISTS
(SELECT *
FROM sysman.mgmt$metric_current i
WHERE I.TARGET_GUID = O.MEMBER_TARGET_GUID
AND metric_name = 'archFull'
AND Metric_Column = 'archTotal'
AND metric_label = 'Archive Area'
AND column_label = 'Total Archive Area (KB)'
AND key_value = 'NOARCHIVELOG'
));Another way to achieve the goal is to push extended metrics (SELECT LOG_MODE FROM V$DATABASE) on each DB, and monitor the values they return to the repository. This is an example for a (slightly) different problem - http://iiotzov.wordpress.com/2012/08/08/how-to-use-the-new-oem-12c-metric-extensions-to-enforce-enterprise-wide-custom-policies .
OEM Repository has many other great uses as well - http://iiotzov.files.wordpress.com/2012/05/oem-repository-a-second-look.doc , http://iiotzov.files.wordpress.com/2011/08/iotzov_oem_repository.pdf
Iordan Iotzov
http://iiotzov.wordpress.com/ -
Do i have to use JNDI with EJBS?
Hi
I want to use JNDI to lookup a system which i will send messages to using JMS. I would like to have some java classes on Tomcat to do the job. But...whenever i hear about JNDI it is always in relation to EJBs. Can i only use JNDI with EJBS?
If i can use JNDI is there anything important i need to know about.
Thanks in advance!
San H.You can definitely use JNDI outside of EJB's - in particular, it's a great interface for dealing with LDAP servers, even securely, and can also be used for DNS interfacing, COS, RMI registries, etc.
While JNDI was chosen as the method by which J2EE components can locate other components in a distributed environment, it's by no means limited to that task :) It's a wonderful API, and in terms of things you need to know, most everything is covered fairly well at the JNDI tutorial in the various trails that are mapped out there.
http://java.sun.com/products/jndi/tutorial/
Good luck!
James
James Manning | Principal Engineer
Porivo Technologies, Inc.
919.806.0566 | [email protected]
http://www.porivo.com/
Measuring end-to-end Web performance.
Register for a FREE Performance appraisal:
http://www.porivo.com/peerReview/eval.html -
Help Connecting A Stateless Session Bean To MySQL Database
Hi, I'm trying to connect a simple stateless session bean that has been
deployed using the admin console to a MySQL database that has been
set up and pinged using the JDBC Resources/Connection Pools part of the
admin console.
When I attempt to connect to the database using the session bean I get the
following error message:
Exception in thread "main" java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.RemoteException: ; nested exception is:
java.sql.SQLException: No database selected
at com.sun.corba.ee.impl.javax.rmi.CORBA.Util.mapSystemException(Util.java:161)
at javax.rmi.CORBA.Util.mapSystemException(Unknown Source)
at com.sun.corba.ee.impl.presentation.rmi.StubInvocationHandlerImpl.invoke(StubInvocationHandlerImpl.java:142)
at com.sun.corba.ee.impl.presentation.rmi.bcel.BCELStubBase.invoke(Unknown Source)
at DBDynamicStub.testDatabase(_DB_DynamicStub.java)
at DBClient.main(DBClient.java:9)
Caused by: java.rmi.RemoteException: ; nested exception is:
java.sql.SQLException: No database selected
at com.sun.ejb.containers.InvocationHandlerUtil.throwRemoteException(InvocationHandlerUtil.java:96)
at com.sun.ejb.containers.EJBObjectInvocationHandler.invoke(EJBObjectInvocationHandler.java:141)
at $Proxy26.testDatabase(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie._invoke(ReflectiveTie.java:123)
at com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispatchToServant(CorbaServerRequestDispatcherImpl.java:648)
at com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispatch(CorbaServerRequestDispatcherImpl.java:192)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequestRequest(CorbaMessageMediatorImpl.java:1709)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:1569)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleInput(CorbaMessageMediatorImpl.java:951)
at com.sun.corba.ee.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback(RequestMessage_1_2.java:181)
at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:721)
at com.sun.corba.ee.impl.transport.SocketOrChannelConnectionImpl.dispatch(SocketOrChannelConnectionImpl.java:469)
at com.sun.corba.ee.impl.transport.SocketOrChannelConnectionImpl.doWork(SocketOrChannelConnectionImpl.java:1258)
at com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:409)
Caused by: java.sql.SQLException: No database selected
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2851)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1531)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1622)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2379)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2306)
at com.mysql.jdbc.Statement.executeQuery(Statement.java:1192)
at DBBean.testDatabase(DBBean.java:45)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.sun.enterprise.security.SecurityUtil$2.run(SecurityUtil.java:153)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.enterprise.security.application.EJBSecurityManager.doAsPrivileged(EJBSecurityManager.java:950)
at com.sun.enterprise.security.SecurityUtil.invoke(SecurityUtil.java:158)
Obviously this means that the bean can't connect to the database but I am
unsure why this is. When I set up the database using the admin console
I set the the jndi name to jdbc/test and I've tried using the following look up
code to find the database that is referenced by the JNDI name:
Context context = new javax.naming.InitialContext();
DataSource ds = (DataSource) context.lookup("jdbc/test");
and also
Context context = new javax.naming.InitialContext();
DataSource ds = (DataSource)context.lookup("java:comp/env/jdbc/test");
Neither of these methods work.
When I look at the JNDI Tree Browsing window which is available from the
admin console there is no mention of the database at all, there are four
items in the three, they are:
UserTransaction
->jdbc
->ejb
DBBean
Do I need to add a JNDI reference somewhere in order for the bean to locate
the database? I thought that when I created the database in the admin
console and specified a JNDI name this would be all that's required in order
for beans to locate the database, obviously not.
If anyone can offer any advice at all I would be very very grateful.
Ianstmt.execute("use YOUR_DATABASE_NAME");
// then your db queries.This approach works for me.
It also works to specify the database in the query like this:
InitialContext initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
DataSource ds = (DataSource) envCtx.lookup("jdbc/myDB");
Connection conn = ds.getConnection();
try {
Statement statement = conn.createStatement();
ResultSet rs = statement.executeQuery("select * from myDB.news");
...As you can see I added myDB. to the query.
But why is this necessary?
If I use DriverManager instead, this is NOT necessary. Like this:
Connection connection = null;
try {
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/myDB", "username", "password");
Statement statement = connection.createStatement();
ResultSet rs = statement.executeQuery("select * from news");
...Why do I not have to run the query statement.execute("use YOUR_DATABASE_NAME"); or specify the database name in the query statement.executeQuery("select * from myDB.news"); when I use DriverManager to obtain a Connection when I have to do that when using a DataSource?
It don't seem very efficient to have to run the extra query ( use db-name ) before I run any other query in my application. -
BOE XI 3.1 Mysql database connection jar
Hi All,
I am new learner for BOE.I installed Business Object Enterpraise 12.0.
I have created the report WebI rich client and saved in local path, and also some value insert into mysql database table.
I need to know how its stored into mysql database.
which jar file is used for creating the connection with mysql database .
Thanks,
Yousuf
Edited by: yousufalam on Dec 31, 2010 12:40 PMThe connection objects are store in the CI_APPOBJECTS repository table with SI_KIND='Metadata.DataConnection' . The connection properties are stored as property bags along with your objects.
Unfortunately I have just found a reference that this kind of access in not fully supported though and you may have to use the Universe Designer SDK (COM based)
Change password of Universe connection using Java SDK?
Since you are working with the SDK it will make sense to post your questions here:
Java SDK Application Development
Regards,
Stratos -
How use Jndi datasoure in Jserver?
Hi,
I want to deploy EJB to jserver. The EJB use JNDI jdbc2.0 datasource to access database. But there only are some sujects how to use JNDI jdbc datasoure in client application in oracle8i 8.1.6 jdbc 2.0 document, no in Jserver. Which one could tell me how to use JNDI jdbc datasoure in Oracle 8.1.6 Jserver.
Thanks in advance.
sun xifengYou have JServer discussion group to post JServer related questions.
Please repost it there.
raghu -
Hi,
I want to deploy EJB to jserver. The EJB use JNDI jdbc2.0 datasource to access database. But there only are some sujects how to use JNDI jdbc datasoure in client application in oracle8i 8.1.6 jdbc 2.0 document, no in Jserver. Which one could tell me how to use JNDI jdbc datasoure in Oracle 8.1.6 Jserver.
Thanks in advance.
sun xifeng
nullYou have JServer discussion group to post JServer related questions.
Please repost it there.
raghu -
MIgration from MYSQL database to Oracle database
HI,
Can you pls let me know how can we do this using Oracle SQL Developer.
In Mysql database we are having one table which is not normalized and corresponding to it we have created normalized tables in oracle database.
so scenario is like this
EMP table in MYSQL database ----------- need to migrate to----> Employee table
Dept table.
These tables are having some extra columns also which are not there in EMP table in MYSQL database.
SO we want to fill some default values for the new columns while doing the migration.
Can you pls let me know if this is achievable through SQL Developer and how?Sorry, you'd have to do this in 2 steps:
1. Migrate the tables as they are.
2. Insert the rows from the migrated tables into the new ones.
Have fun,
K. -
Having Trouble Linking mySQL Database to Website
I am considering a move of all my websites into Azure and setup a test account this afternoon with the free trial. I've been able to setup the website; however, I'm having issues with the creation - more specifically the linkage - of a MySQL database
to the site. I've tried to link the database in a number of ways including both the existing and preview portals in addition to trying to create the new resource instead of linking. In each scenario the database is created but the linkage fails.
The message I keep getting is:
Could not link resource '>DB Name>' to web site '<Site Name>'.
Am I doing something wrong?hi sir,
Thanks for you posting!
Firstly, please make sure your MySQL database in host on Azure, not in your project.
Secondly, if your database is create on Azure, I suggest you could try those step:
1.delete the entire website
2.create a new website and select add the existing MySQL database as a Linked Resource .
Also, please see this similar issue post:
http://stackoverflow.com/a/12198776
Regards,
Will
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey. -
Create base dn using JNDI...
Hi
I want to create the base dn for OpenDJ LDAP using JNDI below is the code i am using for the same but it is thorwing me the error could any body help me to tell me where exactly i am doing wrong .
public static String ldapUri = "ldap://169.144.104.75:389";
public static String admindn = "cn=Directory Manager";
public static String admincred = "redhat";
public static void main(String args[]){
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, ldapUri);
env.put( Context.SECURITY_PRINCIPAL, admindn );
env.put( Context.SECURITY_CREDENTIALS, admincred );
try {
DirContext ctx = new InitialDirContext(env);
Attributes attrs = new BasicAttributes(true);
Attribute objclass = new BasicAttribute("objectclass");
objclass.add("top");
objclass.add("domain");
objclass.add("ds-cfg-branch");
attrs.put(objclass);
attrs.put("dn","ds-cfg-backend-id=userRoot,cn=Backends,cn=config");
ctx.createSubcontext("dc=naren1,dc=naren1",attrs);
ctx.close();
The error is am getting is
javax.naming.NameNotFoundException: [LDAP: error code 32 - The provided entry dc=naren1,dc=naren1 cannot be added because its suffix is not defined as one of the suffixes within the Directory Server]; remaining name 'dc=naren1,dc=naren1'
at com.sun.jndi.ldap.LdapCtx.mapErrorCode(LdapCtx.java:3057)
at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2978)I want to create the base dn on the OpenDJ and i have used the above mentioned code to create the basedn .
I am the confing file where this entry should be created
dn: ds-cfg-backend-id=userRoot,cn=Backends,cn=config
objectClass: ds-cfg-backend
objectClass: top
objectClass: ds-cfg-local-db-backend
ds-cfg-preload-time-limit: 0 seconds
ds-cfg-compact-encoding: true
ds-cfg-db-checkpointer-bytes-interval: 20 megabytes
ds-cfg-db-logging-level: CONFIG
ds-cfg-db-checkpointer-wakeup-interval: 30 seconds
ds-cfg-disk-full-threshold: 20 megabytes
ds-cfg-db-evictor-keep-alive: 600 seconds
ds-cfg-disk-low-threshold: 100 megabytes
ds-cfg-db-directory: db
ds-cfg-base-dn: dc=com
ds-cfg-base-dn: dc=ex,dc=com1
ds-cfg-base-dn: dc=exam,dc=com2
I have also read one artical on the same http://stackoverflow.com/questions/8977946/how-to-create-new-base-dn-using-jndi
But unable to find the error . If any body can help who had worked on to create the base dn on LDAP. -
Servlet with Issues writing to MySQL Database using JNDI
I'm hung on one servlet for my site. It compiles fine, and is accessed fine by the JSP, but doesn't do as I intended: write my blog entries to the MySQL database!
As mentioned in the title, I'm using JNDI for connection pooling, via META-INF/context.xml.
I'm also using JDBC Realm with a form, and that's working just fine, so I'm sure my issue isn't context.xml, as it seems to be overriding Tomcat's context file just fine, at least for authentication.
Below is the code from the servlet, to include the annotations:
package projectEgress.web.blog;
import java.io.*;
import java.text.*;
import java.sql.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.*;
public final class blogInput {
/* bean properties */
private String blogHeader;
private String blogSubheader;
private String blogBody;
private String externalLinks;
Connection conn;
Statement stmt;
/* getters & setters */
public String getBlogHeader() {
return blogHeader;
public void setBlogHeader(String blogHeader) {
this.blogHeader = blogHeader;
public String getBlogSubheader() {
return blogSubheader;
public void setBlogSubheader(String blogSubheader) {
this.blogSubheader = blogSubheader;
public String getBlogBody() {
return blogBody;
public void setBlogBody(String blogBody) {
this.blogBody = blogBody;
public String getExternalLinks() {
return externalLinks;
public void setExternalLinks(String externalLinks) {
this.externalLinks = externalLinks;
/* like it says, a void which writes to the database */
public void writeToDatabase() {
/* create the query string to fill the table */
String query = "insert into blogEntry (blogHeader, blogSubheader, blogBody, externalLinks) values (\"" + this.blogHeader + "\", \"" + this.blogSubheader + "\", \"" + this.blogBody + "\", \"" + this.externalLinks + "\")";
try {
/*establish the datasource and make the connection */
Context ctxt = new InitialContext();
DataSource dsrc = (DataSource)ctxt.lookup("java:comp/env/jdbc/projectEgress");
conn = dsrc.getConnection();
stmt = conn.createStatement();
/* Add data to table 'blogEntry' in our database */
int input = stmt.executeUpdate(query);
/* close the connections */
stmt.close();
conn.close();
/* check for exceptions, ensure connections are closed */
} catch (SQLException sqlx) {
sqlx.printStackTrace();
} catch (Exception ex) {
ex.printStackTrace();
} finally {
if (stmt != null) {
try {
stmt.close();
} catch (SQLException sqlx) {}
if (conn != null) {
try {
conn.close();
} catch (SQLException sqlx) {}
Here are the settings I have in META-INF/context.xml (sans Realm stuff, which works):
<Context debug="1" reloadable="true">
<Resource name="jdbc/projectEgress"
auth="Container"
type="javax.sql.DataSource"
username="********"
password="********"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/projectEgress?autoReconnect=true"
validationQuery="select 1"
maxActive="15"
maxIdle="8"
removeAbandoned="true"
removeAbandonedTimeout="120" />
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<WatchedResource>META-INF/context.xml</WatchedResource>
</Context>And, finally, the code I'm using in the JSP which calls the method (the form action is directed to this file's URL):
<jsp:useBean id="blogInput" class="projectEgress.web.blog.blogInput">
<jsp:setProperty name="blogInput" property="*" />
<jsp:scriptlet>blogInput.writeToDatabase();</jsp:scriptlet>
</jsp:useBean>
-YES, I know I'm using a scriptlet in a JSP... I really don't want to create a custom tag to call the method, at least not until I'm far along enough in the project to justify creating a library... let's make it all work, first! :o)
FINALLY, the form:
<form action="/projectEgress/area51/blogInput" method="post" id="adminForm" enctype="application/x-www-form-urlencoded">
<div>
<span class="inputheader">Blog Header</span><br />
<input type="text" name="blogHeader" size="35" class="form" /><br />
<span class="inputheader">Blog SubHeader</span><br />
<input type="text" name="blogSubheader" size="45" class="form" /><br />
<span class="inputheader">Blog Body</span><br />
<textarea class="content" name="blogBody" rows="9" cols="60"></textarea><br />
<span class="inputheader">External Links</span><br />
<input type="text" name="externalLinks" size="45" class="form" /><br />
<input type="submit" value="Post!" class="submit" />
</div>
</form>As far as I can tell, it should work, and it doesn't throw any errors (in fact it shows the success message rather than the configured error page), but when I check the blogEntry table from the MySQL prompt, it responds with "Empty set".
I've double checked to ensure that the table columns are present in MySQL and all the naming conventions line up and they do, so I figure it's my servlet that's broken.
Advice? Ideas?
Thanks in advance.
Edited by: -Antonio on Apr 25, 2008 8:03 PM with additional infoOkay, I changed a few things in the servlet code.
For one, I'm trying a PreparedStatement in place of Statement. Don't ask me what made me think it would work any better, it just stores the sql query in cache, but I thought I'd just try something else.
One thing this is allowing me to do is make the connection and statement (now PreparedStatement pStmt) objects local variables. It wouldn't allow me to do so before without giving me compile errors.
package projectEgress.web.blog;
import java.io.*;
import java.text.*;
import java.sql.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.*;
public final class blogInput {
/* bean properties */
private String blogHeader;
private String blogSubheader;
private String blogBody;
private String externalLinks;
/* getters & setters */
public String getBlogHeader() {
return blogHeader;
public void setBlogHeader(String blogHeader) {
this.blogHeader = blogHeader;
public String getBlogSubheader() {
return blogSubheader;
public void setBlogSubheader(String blogSubheader) {
this.blogSubheader = blogSubheader;
public String getBlogBody() {
return blogBody;
public void setBlogBody(String blogBody) {
this.blogBody = blogBody;
public String getExternalLinks() {
return externalLinks;
public void setExternalLinks(String externalLinks) {
this.externalLinks = externalLinks;
/* like it says, a void which writes to the database */
public synchronized void writeToDatabase() {
Connection conn = null;
PreparedStatement pStmt = null;
/* create the query string to fill the table */
String Query = "INSERT INTO blogEntry (blogHeader, blogSubheader, blogBody, externalLinks) VALUES (\"" + this.blogHeader + "\", \"" + this.blogSubheader + "\", \"" + this.blogBody + "\", \"" + this.externalLinks + "\")";
try {
/*establish the datasource and make the connection */
Context ctxt = new InitialContext();
DataSource dsrc = (DataSource)ctxt.lookup("java:comp/env/jdbc/projectEgress");
conn = dsrc.getConnection();
pStmt = conn.prepareStatement(Query);
/* Add data to table 'blogEntry' in our database */
pStmt.executeUpdate();
pStmt.clearParameters();
/* close the connections */
pStmt.close();
conn.close();
/* check for exceptions, ensure connections are closed */
} catch (SQLException sqlx) {
sqlx.printStackTrace();
} catch (Exception ex) {
ex.printStackTrace();
} finally {
if (pStmt != null) {
try {
pStmt.close();
} catch (SQLException sqlx) {}
if (conn != null) {
try {
conn.close();
} catch (SQLException sqlx) {}
}Someone out there has to have a thought on this.
Even if it's just something they think probably won't work, so long as it gives me another angle to see this from. -
Error connecting to MySQL database using JNDI
Hi,
I'm trying to do a simple connection to a MySQL database using the JNDI look-up
method.
Have tried this with the PointBase database that came with WebLogic and got it
to work successfully.
However got the attached error message when I tried it on MySQL database. I tried
this with both the WebLogic's driver for MySQL and also the one I downloaded from
MySQL (com.mysql.jdbc.Driver), and both failed with the same error message.
Offhand, it doesn't look like the connection pool is failing. Tested it with WebLogic's
"Test Pool" function and it was alright.
Also MySQL database is working properly. Test this by doing simple connection
and retrieval with simple JDBC connections and it works.
Any ideas what else I can check with regards to this problem?
Thanks!
[att1.html]Hi Joe,
Attached is the config.xml for the domain that I'm working with. There are 3 connection
pools set-up.
The problematic Connection Pools are "MySQLCP" and "My JDBC Connection Pool"
Thanks for your help in this!
Joe Weinstein <[email protected]> wrote:
show us the pool definition, as it is in the config.xml file.
thanks
joe
Everbright wrote:
Hi,
I'm trying to do a simple connection to a MySQL database using theJNDI look-up
method.
Have tried this with the PointBase database that came with WebLogicand got it
to work successfully.
However got the attached error message when I tried it on MySQL database.I tried
this with both the WebLogic's driver for MySQL and also the one I downloadedfrom
MySQL (com.mysql.jdbc.Driver), and both failed with the same errormessage.
Offhand, it doesn't look like the connection pool is failing. Testedit with WebLogic's
"Test Pool" function and it was alright.
Also MySQL database is working properly. Test this by doing simpleconnection
and retrieval with simple JDBC connections and it works.
Any ideas what else I can check with regards to this problem?
Thanks!
Error 500--Internal Server Error
java.sql.SQLException: Cannot obtain connection: driverURL = jdbc:weblogic:pool:MyJDBCConnection Pool, props = {enableTwoPhaseCommit=false, jdbcTxDataSource=true,
connectionPoolID=MyJDBC Connection Pool, dataSourceName=MyJDBC Data
Source}.
Nested Exception: java.lang.RuntimeException: Failed to Generate WrapperClass
at weblogic.utils.wrapper.WrapperFactory.createWrapper(WrapperFactory.java:141)
at weblogic.jdbc.wrapper.JDBCWrapperFactory.getWrapper(JDBCWrapperFactory.java:73)
at weblogic.jdbc.pool.Driver.allocateConnection(Driver.java:242)
at weblogic.jdbc.pool.Driver.connect(Driver.java:158)
at weblogic.jdbc.jts.Driver.getNonTxConnection(Driver.java:444)
at weblogic.jdbc.jts.Driver.connect(Driver.java:138)
at weblogic.jdbc.common.internal.RmiDataSource.getConnection(RmiDataSource.java:298)
at jsp_servlet.__index._jspService(__index.java:142)
at weblogic.servlet.jsp.JspBase.service(JspBase.java:33)
at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:1053)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:387)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:305)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6310)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:317)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:118)
at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3622)
at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2569)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:197)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:170)
at weblogic.jdbc.jts.Driver.wrapAndThrowSQLException(Driver.java:395)
at weblogic.jdbc.jts.Driver.getNonTxConnection(Driver.java:448)
at weblogic.jdbc.jts.Driver.connect(Driver.java:138)
at weblogic.jdbc.common.internal.RmiDataSource.getConnection(RmiDataSource.java:298)
at jsp_servlet.__index._jspService(__index.java:142)
at weblogic.servlet.jsp.JspBase.service(JspBase.java:33)
at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:1053)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:387)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:305)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6310)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:317)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:118)
at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3622)
at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2569)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:197)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:170)
[config.xml]
Maybe you are looking for
-
Sales orders with credit issues taking availability stock
Hi, I am doing confirmation using Global ATP in APO. The confirmation is well done, but the confirmed quantity for sales orders with clients that have credit issues is taken the available sotck for other sales orders with ok clients that I want to co
-
Solution Manager 7 EHP1 - Implimentation Help
Dear All, I am new to Solution Manager. I have install Solution Manager 7 EHP1 (ABAP+JAVA) on windows 2003 and applied later SP stack 24 available at Market place. We have SAP ECC 6, ABAP stack (we have not install JAVA stack for DEV/QAS or PRD Serve
-
DJ sets & rare songs gone because of itunes match
I;ve tried searchign for answers on this matter and come up hopeless! I have lots of dj sets and rare songs, and the whole point of getting this subscription for me was to not have to delete them. Now it seems they are gone. My phone is plugged into
-
Dear All, camera is not working i have trying to tack picture but facing the problems after push the camera button this massage are showing "Could not start the camera. Close other applications and try opening the camera again" Model No. Curve 8320
-
Hi, I need to lock STRs while creating STO. Can you pls help me with the function module. I looked for ENQUEUE FM for STR lock.But couldn't find it. Pls help Thanks Ram