[jboss-user] [Beginners Corner] - Re: SQLException

jotnarta do-not-reply at jboss.com
Mon Feb 16 08:42:03 EST 2009


Ok, following is my msql-ds.xml file, and the configuration to connect to MySQL database, specifically, mysql schema:

  | <?xml version="1.0" encoding="UTF-8"?>
  | 
  | <datasources>
  | 
  |     <local-tx-datasource>
  | 
  |     <jndi-name>DefaultDS</jndi-name>
  | 
  |     <connection-url>jdbc:mysql://localhost:3306/mysql</connection-url>
  | 
  |     <driver-class>com.mysql.jdbc.Driver</driver-class>
  | 
  |     <user-name>root</user-name>
  | 
  |     <password>admin</password>
  | 
  |     <valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLValidConnectionChecker</valid-connection-checker-class-name>
  | 
  |     <metadata>
  | 
  |     <type-mapping>mySQL</type-mapping>
  | 
  |     </metadata>
  | 
  |     </local-tx-datasource>
  | 
  | </datasources>
  | 

and following is the jsp file that I am trying to connect my schema which was defined in the previous xml file:


  | <%@page import="java.util.*,javax.naming.*,javax.sql.DataSource,java.sql.*"%>
  | <%
  | 	DataSource ds = null;
  | 	Connection con = null;
  | 	//Statement st = null;
  | 	InitialContext ic;
  | 	
  | 	try {
  | 		ic = new InitialContext();
  | 		ds = (DataSource) ic.lookup("java:/DefaultDS");
  | 		con = ds.getConnection();
  | 		Statement st = con.createStatement();
  | 		ResultSet rs = st.executeQuery("select * from db");
  | 		
  | 		while(rs.next()) {
  | 			out.println("<br> " + rs.getString("ID"));
  | 		}
  | 		rs.close();
  | 		st.close();
  | 		
  | 		out.println("DONE");
  | 	} catch (Exception e) {
  | 		out.println("Exception thrown " + e );
  | 		//e.printStackTrace();
  | 	} finally {
  | 		if (con != null) {
  | 			con.close();
  | 		}
  | 	}
  | %>
  | 

Do you have any comments ????

View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4210336#4210336

Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4210336



More information about the jboss-user mailing list