• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Data Source Connection with MySQL

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have been working my way through the book "Beginning Java EE 5" using eclipse and jboss with mysql. In Chap 7 they have an example that is using a DataSource and connection in a JSP. I want to have it connect to MySQL database. I created a database called DataSourceExample and added a table to it and two records.

I wanted to attaching the original DataSourceExample.jsp files but they are not allowed.

My question is what do I change to connect to the MySQL database?

Part of the code from DataSourceExample.jsp

<% InitialContext context = new InitialContext();
DataSource dataSource =
(DataSource) context.lookup("java:comp/env/jdbc/DataSourceExample");
Connection conn = null;
Statement stmt = null;
ResultSet rset = null;
try {
conn = dataSource.getConnection();

Here is the original web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5" >
<display-name>DataSourceExample</display-name>
<servlet>
<display-name>DataSourceExample</display-name>
<servlet-name>DataSourceExample</servlet-name>
<jsp-file>/DataSourceExample.jsp</jsp-file>
</servlet>
<resource-ref>
<res-ref-name>jdbc/DataSourceExample</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
<welcome-file-list>
<welcome-file>DataSourceExample.jsp</welcome-file>
</welcome-file-list>
</web-app>
 
Ranch Hand
Posts: 859
IBM DB2 Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you need a ???-ds.xml (datasource xml file) which contains the physical server address port, userid password etc.

something like (This is DB2): (Provide your own values for $VALUES$)


WP
 
Jeanne Harris
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am running with JBOSS 7.0

I created the file called my-ds.xml and put it into the WebContent\WEB-INF directory.

<datasources>
<local-tx-datasource>
<jndi-name>jdbc/DataSourceExample</jndi-name>
<connection-url>
jdbc:mysql://localhost:3306/DataSourceExample
</connection-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<user-name>root</user-name>
<password>my password</password>
</local-tx-datasource>
</datasources>

When I run I get this error message.

Here is the whole jsp file.



07:08:23,802 INFO [org.jboss.as.deployment] (DeploymentScanner-threads - 2) Found 07-exp1.war in deployment directory. To trigger deployment create a file called 07-exp1.war.dodeploy
07:08:23,824 INFO [org.jboss.as.server.deployment] (MSC service thread 1-4) Starting deployment of "07-exp1.war"
07:08:24,058 INFO [org.jboss.as.server.controller] (DeploymentScanner-threads - 1) Deployment of "07-exp1.war" was rolled back with failure message {"Services with missing/unavailable dependencies" => ["jboss.deployment.unit.\"07-exp1.war\".jndiDependencyService missing [ jboss.naming.context.java.module.07-exp1.07-exp1.env/jdbc/DataSourceExample ]","jboss.naming.context.java.module.07-exp1.07-exp1.env/jdbc/DataSourceExample.jboss.deployment.unit.\"07-exp1.war\".module.07-exp1.07-exp1.0 missing [ jboss.naming.context.java.module.07-exp1.07-exp1.env/jdbc/DataSourceExample ]"]}
07:08:24,064 INFO [org.jboss.as.server.deployment] (MSC service thread 1-3) Stopped deployment 07-exp1.war in 6ms
07:08:24,066 ERROR [org.jboss.as.deployment] (DeploymentScanner-threads - 2) {"Composite operation failed and was rolled back. Steps that failed:" => {"Operation step-2" => {"Services with missing/unavailable dependencies" => ["jboss.deployment.unit.\"07-exp1.war\".jndiDependencyService missing [ jboss.naming.context.java.module.07-exp1.07-exp1.env/jdbc/DataSourceExample ]","jboss.naming.context.java.module.07-exp1.07-exp1.env/jdbc/DataSourceExample.jboss.deployment.unit.\"07-exp1.war\".module.07-exp1.07-exp1.0 missing [ jboss.naming.context.java.module.07-exp1.07-exp1.env/jdbc/DataSourceExample ]"]}}}

Jeanne
 
Jeanne Harris
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For a test I created a simple java project with one file called Main.java and deployed it as a Java App and it runs with no errors. I accessed the database and display the two records and three fields as expected. I am missing or have an error in my jsp projects environment somewhere.

 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic