Could some of these blank properties be a problem?
Where do you set the name of the datasource?
Joined: Feb 23, 2007
Hi, I tried the code after removing the blank properties fields. But got the same exception. As these fields are optional these shouldn't affect the outcome if not given. I set the name of the datasource in the file mysql-ds.xml which is in the server\default\deploy directory of JBoss. Also JBoss gives the following line in the startup:
14:12:44,577 INFO [ConnectionFactoryBindingService] Bound ConnectionManager 'jboss.jca:service=DataSourceBinding,name=MySqlDS' to JNDI name 'java:MySqlDS'
contents of mysql-ds.xml : --------------------------
<blockquote>code:<pre name="code" class="core"> <datasources> <local-tx-datasource> <jndi-name>MySqlDS</jndi-name> <connection-url>jdbc:mysql://localhost:3306/jbossdb</connection-url> <driver-class>com.mysql.jdbc.Driver</driver-class> <user-name>root</user-name> <password>root</password> <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name> <!-- should only be used on drivers after 3.22.1 with "ping" support <valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLValidConnectionChecker</valid-connection-checker-class-name> --> <!-- sql to call when connection is created <new-connection-sql>some arbitrary sql</new-connection-sql> --> <!-- sql to call on an existing pooled connection when it is obtained from pool - MySQLValidConnectionChecker is preferred for newer drivers <check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql> -->
<!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml --> <metadata> <type-mapping>mySQL</type-mapping> </metadata> </local-tx-datasource> </datasources>
Originally posted by Siddharth Bhargava: Even with java:/ it is not working.....
What error message are you seeing? Look back through the log to make sure the DataSource is properly configured. Just telling us it is not working doesn't allow us to offer much advice. How is it "not working"?
Joined: Feb 23, 2007
JBoss console doesn't shows anything. It just displays the following thing in the console....
17:58:56,493 INFO [ConnectionFactoryBindingService] Bound ConnectionManager 'jboss.jca:service=ConnectionFactoryBinding,name=JmsXA' to JNDI name 'java:JmsXA' 17:58:56,618 INFO [ConnectionFactoryBindingService] Bound ConnectionManager 'jboss.jca:service=DataSourceBinding,name=MySqlDS' to JNDI name 'java:MySqlDS' 17:58:56,712 INFO [TomcatDeployer] deploy, ctxPath=/jmx-console, warUrl=.../deploy/jmx-console.war/ 17:58:57,181 INFO [Http11Protocol] Starting Coyote HTTP/1.1 on http-127.0.0.1-8080 17:58:57,212 INFO [AjpProtocol] Starting Coyote AJP/1.3 on ajp-127.0.0.1-8009 17:58:57,212 INFO [Server] JBoss (MX MicroKernel) [4.2.2.GA (build: SVNTag=JBoss_4_2_2_GA date=200710221139)] Started in 29s:172ms
Eclipse shows the following exception on console
Hi.... log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment). log4j:WARN Please initialize the log4j system properly. Hello Could not find datasource Exception in thread "main" java.lang.NullPointerException at com.example.jndi.SaveExample.main(SaveExample.java:51)
By default, the datasources in JBoss are bound to java: namespace and are not visible outside the server JVM (your code in Eclipse runs in its own separate JVM), to remote clients. See this for more details.
And yes, if this still does not solve your issue, then as Mark said, please post the code.
Hi Mark, No I am not running JBoss through Eclipse. I am running eclipse separately. Yeah it may be possible that Eclipse isn't connecting to JBoss because everytime it gives Could not find Datasource exception. How could I make them connect to each other. ?
By default, the datasources in JBoss are bound to java: namespace and are not visible outside the server JVM (your code in Eclipse runs in its own separate JVM), to remote clients.
So what's the solution to this if I want to make a JNDI bound SessionFactory and I am running a Java program from Eclipse and Jboss AS app. server in a separate window. Please Help me I am struggling. !!!