#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2002
    Posts
    8
    Rep Power
    0

    jsp, jdbc driver, mysql


    I have installed and run tomcat successfully, and have also installed mysql successfully. I have also downloaded the mysql driver and set the classpath as instructed:
    SET CLASSPATH=%CLASSPATH%;C:\jdk1.3.0_02\bin;C:\jdk1.3.0_02\lib\mm.mysql-2.0.11\mm.mysql-2.0.11-bin.jar

    In spite of all this, I am still getting the following error:
    javax.servlet.ServletException: No suitable driver...etc...etc...

    Here is the code for my test page, which I am running from the tomcat examples directory:

    <%@ page language="java" import="java.sql.*" %>
    <body>
    <%
    Class.forName("org.gjt.mm.mysql.Driver").newInstance();

    java.sql.Connection conn;
    conn = DriverManager.getConnection("jdbc:mysql//localhost/TestDb01?user=myname&password=mypassword");

    Statement stmt = conn.createStatement();

    // change this as per your requirements
    String query = "select * from er_tb_fieldchoices";

    ResultSet myResultSet = stmt.executeQuery(query);

    if (myResultSet != null) {
    while (myResultSet.next()) {
    // specify the field name
    String name = myResultSet.getString("User");

    %>

    <%= name %>
    <br>
    <%
    }
    }

    stmt.close();

    conn.close();
    %>

    Thanks in advance for any thoughts you can offer.
  2. #2
  3. No Profile Picture
    Clueless llama
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Feb 2001
    Location
    Lincoln, NE. USA
    Posts
    2,353
    Rep Power
    117
    Not sure if it will help or not, but I have heard of some problems sending the username and pass on the query string. try this instead:
    Code:
    	try {
                    String host = "localhost";
                    String port = "";//whatever port you are running on. 
                    String dbName = "TestDb01";
                    String uid = "myName";
                    String pw = "myPassword";
    
    		Class.forName("org.gjt.mm.mysql.Driver");
    		String dbType = "jdbc:mysql:";
    		String url = dbType + "//" + host + ":" + port + "/" + dbName;
    		conn = DriverManager.getConnection(url, uid, pw);
    
              /* more code */
    
    	}
    	catch (ClassNotFoundException cnfe) { cnfe.printStackTrace(); }
    	catch (SQLException sqle) { sqle.printStackTrace(); }

IMN logo majestic logo threadwatch logo seochat tools logo