[jboss-user] [JNDI/Naming/Network] - Jboss with mySql

jbossnatasha do-not-reply at jboss.com
Thu Aug 24 18:07:45 EDT 2006


Hello,

I need urgent help with my application. I am trying to connect to MySql with jboss and getting error.

My mysql-ds.xml looks like this:

<?xml version="1.0" encoding="UTF-8"?>

<!-- $Id: mysql-ds.xml,v 1.3.2.3 2006/02/07 14:23:00 acoliver Exp $ -->
<!--  Datasource config for MySQL using 3.0.9 available from:
http://www.mysql.com/downloads/api-jdbc-stable.html
-->


  <local-tx-datasource>
    <jndi-name>MySqlDS</jndi-name>
    <connection-url>jdbc:mysql://desktop/employee</connection-url>
    <driver-class>org.gjt.mm.mysql.Driver</driver-class>
    <user-name>root</user-name>
    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 (optional) -->
    
       <type-mapping>mySQL</type-mapping>
    
  </local-tx-datasource>



_-----------------------------------------

I have all the jndi.jar, fsconfig.dar, providerURL.jar in the JAVA_HOME/jre/lib/ext folder.

The jdbc driver is set correctly, I know, as I can connect to the database usin the DriverManager code.
-----------------------------------------------

my application code is:


import java.io.*;   
import javax.naming.*;
import java.net.*;
import java.sql.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.sql.*;

public class ShowBedrock extends HttpServlet 
{
    /**
	 * 
	 */
	private static final long serialVersionUID = 4920882690562885989L;

	public String getServletInfo()
    {
       return "Servlet connects to MySQL database and displays result of a SELECT";
    }

    // Use http GET

    public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
       
    	Context ctx;

    	Hashtable env = new Hashtable();
    	env.put(Context.INITIAL_CONTEXT_FACTORY, 
    	    "com.sun.jndi.fscontext.RefFSContextFactory");
    	env.put(Context.PROVIDER_URL, "jdbc:mysql://desktop/employee");
    	
        // Output stream to STDOUT
        PrintWriter out = response.getWriter();
        try
        {
    	ctx = new InitialContext(env);
        response.setContentType("text/html");    // Response mime type

        out.println("Bedrock");
        out.println("<H1>Bedrock</H1>");

              String name = "java:MySqlDS";
        	DataSource ds = (DataSource) ctx.lookup(name);
              
        	  Connection conn;
 
              Statement statement;
              
              conn = ds.getConnection();

              String query = "SELECT name, dept, ";
              query +=       "       jobtitle ";
              query +=       "FROM   employee ";
              
              statement = conn.createStatement();

              // Perform the query
              ResultSet rs = statement.executeQuery(query);

              out.println("<TABLE border>");

              // Iterate through each row of rs
              while (rs.next())
              {
                  String m_name = rs.getString("name");
                  String m_dept = rs.getString("dept");
                  String m_jobtitle = rs.getString("jobtitle");
                  out.println("" +
                              "" + m_name + "" +
                              "" + m_dept + "" +
                              "" + m_jobtitle + "" +
                              "");
              }

              out.println("");

              rs.close();
              statement.close();
              conn.close();
            }        
        
        catch (NamingException e) {
                System.err.println("Problem looking up " + ": " + e);
            }
        
        catch (SQLException ex) {
              while (ex != null) {
                    System.out.println ("SQL Exception:  " + ex.getMessage ());
                    ex = ex.getNextException ();
                }  // end while
            }  // end catch SQLException

        catch(java.lang.Exception ex)
            {
                out.println("" +
                            "" +
                            "Bedrock: Error" +
                            "\n" +
                            "SQL error in doGet: " +
                            ex.getMessage() + "");
                return;
            }
         out.close();
    }
}


------------------------------------------

I am getting a runtime error

Am I accessing the jndi object correctly in my code


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

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



More information about the jboss-user mailing list