JavaServer Pages (JSP) and JSTL - JSP/MySql and JDBC/MySql

I have downloaded and copied the this Connector/j to lib directory of my java installation dir.

and this Jsp page is working with that.

<%@ page language="java" import="java.sql.*" %>

<%

String driver ="org.gjt.mm.mysql.Driver";

Class.forName(driver).newInstance();

Connection con=null;

ResultSet rst=null;

Statement stmt=null;

try

{

String url="jdbc:mysql://localhost/books?user=root&password=dba";

con=DriverManager.getConnection(url);

stmt=con.createStatement();

out.println("Connected");

}

catch(Exception e)

{

out.println(e.getMessage());

}

%>

But I couldn't get connect with this java file.

import java.sql.*;

publicclass LoadDriver

{

publicstaticvoid main(String[] args)

{

try

{

Connection con=null;

Class.forName("org.gjt.mm.mysql.Driver").newInstance();

String url="jdbc:mysql://localhost/books?user=root&password=dba";

con=DriverManager.getConnection(url);

System.out.println("Connected...");

}

catch (Exception ex)

{

System.out.println(ex.getMessage());

}

}

}

The exception is the name of the driver. how to solve this problem.

[2510 byte] By [Ajaxranda] at [2007-11-14]
# 1
may you are using driver name incorrectly..cam you try this..driverName = "com.mysql.jdbc.Driver";
vrinda_26a at 2007-7-10 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 2
I tried that and its giving the exception again with that driver name.what is the difference between these two drivers.
Ajaxranda at 2007-7-10 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 3
The latest is the official one from [url= http://www.mysql.com/products/connector/j/]MySQL.com[/url].So you're saying it is throwing a ClassNotFoundException? If so, then the classpath / buildpath is simply bad.
BalusCa at 2007-7-10 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 4
I don't know whether is solves your problem or not, but I tend to use 'import java.io.*' in my database connection files.
Nidhuggura at 2007-7-10 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 5

I am using the MySQL Connector/J 5.0 which downloaded from mysql.com. from that pack consist of lot of files. I am using Windows as my O/S and I copied this file mysql-connector-java-5.0.5-bin from the pack and put it to the lib Dir of the JAVA installation directory. and JSP files are working with SJSAS 9.0

But for JAVA files its giving the out put as org.gjt.mm.mysql.Driver in the console.

Ajaxranda at 2007-7-10 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 6

This is the installation Mannual for Connector/j, Only thing i did for now I just copied that jar file and put it to the lib directory in JAVA installation dir. and it works for my JSP apps. but the problem with Java. as the exception its returning this class names.

i used both com.mysql.jdbc.Driver and org.gjt.mm.mysql.Driver

Installing the Driver and Configuring the CLASSPATH

Once you have extracted the distribution archive, you can install the driver by placing mysql-connector-java-[version]-bin.jar in your classpath, either by adding the full path to it to your CLASSPATH environment variable, or by directly specifying it with the command line switch -cp when starting your JVM.

If you are going to use the driver with the JDBC DriverManager, you would use com.mysql.jdbc.Driver as the class that implements java.sql.Driver.

Ajaxranda at 2007-7-10 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 7

I don't know whether is solves your problem or not,

but I tend to use 'import java.io.*' in my database

connection files.

After adding

import java.io.*;

is it connecting to the databases in your machine.

if its working the problem is with my driver configuration.

Ajaxranda at 2007-7-10 > top of java,Enterprise & Remote Computing,Web Tier APIs...