Posted By:
liu_xj
Posted On:
Thursday, February 9, 2006 01:52 AM
these days ,i was confused by ejb. I want to config the DataSource in jbuilderX use ; jboss3.2.5,but always failured.the test programe can't ; find DataSource,throw < <- javax.naming.NameNotFoundException: MySqlDS not bound at org.jnp.server.NamingServer.getBinding (NamingServer.java:495) at org.jnp.server.NamingServer.getBinding (NamingServer.java:503) at org.jnp.server.NamingServer.getObject (NamingServer.java:509) at org.jnp.server.NamingServer.lookup (NamingServer.java:282) ... ... ->> MySqlDS not bound?at i/o console show: < <- 13:21:41,031 INFO
More>>
these days ,i was confused by ejb.
I want to config the DataSource in jbuilderX use ;
jboss3.2.5,but always failured.the test programe can't ;
find DataSource,throw
<
<-
javax.naming.NameNotFoundException: MySqlDS not bound
at org.jnp.server.NamingServer.getBinding
(NamingServer.java:495)
at org.jnp.server.NamingServer.getBinding
(NamingServer.java:503)
at org.jnp.server.NamingServer.getObject
(NamingServer.java:509)
at org.jnp.server.NamingServer.lookup
(NamingServer.java:282)
... ...
->>
MySqlDS not bound?at i/o console show:
<
<-
13:21:41,031 INFO [MySqlDS] Bound connection factory for resource adapter for ConnectionManager 'jboss.jca:service=LocalTxCM,name=MySqlDS to JNDI name 'java:/MySqlDS'
->>
and i see the log file
<
<-
2006-02-09 13:21:41,031 DEBUG [org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory.MySqlDS] Binding object 'org.jboss.resource.adapter.jdbc.WrapperDataSource@117c0eb' into JNDI at 'java:/MySqlDS'
2006-02-09 13:21:41,031 INFO [org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory.MySqlDS] Bound connection factory for resource adapter for ConnectionManager 'jboss.jca:service=LocalTxCM,name=MySqlDS to JNDI name 'java:/MySqlDS'
->>
why??console told me 'MySqlDS'was bound ,why test program can't find it?I don't know!If u know ,please help me!
my config as follows:
1.config %boss_home%/server/default/conf/standardjaws.xml
java:/MySqlDS
<--modify-->
mySQL
<--modify-->
false
...
2.config %jboss_home%/server/default/conf/standardjbosscmp-jdbc.xml
java:/MySqlDS
<--modify-->
mySQL
<--modify-->
...
3.config %jboss_home%/server/default/conf/login-config.xml
...
liuxj
register8
jboss.jca:service=LocalTxCM,name=MySqlDS
4.add %jboss_home%/server/default/deploy/mysql-ds.xml
MySqlDS
jdbc:mysql://localhost:3306/j2ee
com.mysql.jdbc.Driver
liuxj
register8
5.my test java file:
====================================
import javax.naming.*;
import javax.sql.*;
import java.sql.*;
import java.util.Hashtable;
public class MysqlPoolTest {
public MysqlPoolTest() {
EJBHomeFactory factory = null;
Hashtable env = new Hashtable();
env.put
(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
env.put(Context.PROVIDER_URL, "localhost:1099");
env.put("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");
try
{
Context ctx = new InitialContext(env);
Object obj = ctx.lookup("java:/MySqlDS");
DataSource ds = (DataSource) obj;
Connection connect = ds.getConnection();
Statement stmt = connect.createStatement();
ResultSet rs = stmt.executeQuery("select * from article");
if(rs.next()){
System.out.println(rs.getObject("NO"));
}
} catch (NamingException e) {
e.printStackTrace();
} catch(SQLException e1){
e1.printStackTrace();
}
System.out.flush();
System.out.close();
}
public static void main(String a[]){
new MysqlPoolTest();
}
}
=======================================
<<Less