Mysql and Java

Hi,

can you do me a favor got the following exception when I run the below code in the JBuilder4.

java.lang.NoClassDefFoundError: java/sql/Savepoint

at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)

at java.sql.DriverManager.getConnection(DriverManager.java:517)

at java.sql.DriverManager.getConnection(DriverManager.java:177)

at ucsc.Connect.main(Connect.java:17)

Exception in thread "main"

and When I run this program in the command prompt, I got the following exception

D:\>java Connect

Exception in thread "main" java.lang.NoClassDefFoundError: Connect

D:\>

I set CLASSPATH as %JAVA_HOME%\lib\jre\ mysql-connector-java-5.0.4-bin in the Environmental variables.

Can anyone please tell me the reason for that.

Code

Thanks

import java.sql.*;

publicclass Connect

{

publicstaticvoid main (String[] args)

{

Connection conn =null;

try

{

String userName ="root";

String password ="";

String url ="jdbc:mysql://localhost:3306/ucsc";

// ucsc is the database name

Class.forName ("com.mysql.jdbc.Driver");

conn = DriverManager.getConnection(url,"root","");

System.out.println ("Database connection established");

}

catch (Exception e)

{

System.err.println ("Cannot connect to database server");

}

finally

{

if (conn !=null)

{

try

{

conn.close ();

System.out.println ("Database connection terminated");

}

catch (Exception e)

{}

}

}

}

}

[2812 byte] By [ayomia] at [2007-11-26 16:12:58]
# 1

hi there!!

where have u stored ur program?

no class definition found error means it can't find ur program.

have you placed ur program in D Drive or in a folder IN D drive?

In that case in the cmd promp, first go to that directory and then do javac etc...(Have you done set path also?)

eg.

suppose my prog is in d:\kaydee

then in the cmd prompt u will get first:

D:>\

now type

D:\>cd kaydee

D:\kaydee> javac whatever.java

D:\kaydee>java whatever

ur code has nothing to do with anything.......

tell me if this works.....

KayDeEa at 2007-7-8 22:35:40 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2

Hi

Now I got the following message for that code

D:\>javac Connect.java

D:\>java Connect

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

D:\>

my code

import java.sql.*;

import javax.sql.*;

public class Connect

{

public static void main (String[] args)

{

Connection conn = null;

try

{

String userName = "root";

String password = "";

String url = "jdbc:mysql://localhost:3306/ucsc";

Class.forName ("com.mysql.jdbc.Driver");

conn = DriverManager.getConnection (url, userName, password);

System.out.println ("Database connection established");

}

catch (Exception e)

{

System.err.println (e.toString());

}

finally

{

if (conn != null)

{

try

{

conn.close ();

System.out.println ("Database connection terminated");

}

catch (Exception e)

{ }

}

}

}

}

can you tell me where the error is

thanks

ayomia at 2007-7-8 22:35:40 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3

Hi

Now I got the following message for that code

D:\>javac Connect.java

D:\>java Connect

Cannot connect to database server

D:\>

my code

import java.sql.*;

import javax.sql.*;

public class Connect

{

public static void main (String[] args)

{

Connection conn = null;

try

{

String userName = "root";

String password = "";

String url = "jdbc:mysql://localhost:3306/ucsc";

Class.forName ("com.mysql.jdbc.Driver");

conn = DriverManager.getConnection (url, userName, password);

System.out.println ("Database connection established");

}

catch (Exception e)

{

System.err.println ("Cannot connect to database server");

}

finally

{

if (conn != null)

{

try

{

conn.close ();

System.out.println ("Database connection terminated");

}

catch (Exception e) { /* ignore close errors */ }

}

}

}

}

can you tell me the where the error is

Thanks

ayomia at 2007-7-8 22:35:40 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 4

hi

have u added ur driver in the ODBC data sources(control panel stuff?)

U have to do that to make a conenction to the database!!!!!

control panel>administrative tools>Data sources(ODBC)>add>"select the driver for mySQL"etc etc ..

have u done this?

By the way, since u are working in MySQL, do you have the connector(JAR File)?if not download it!!!

oh..i just saw ur ist post..sorry..u already have the connector..that means if it can't find the dbase either u don't have ur driver set up OR :-

where u have stored mySQL, go to bin and double click on mysqld.exe, and then continue.

Message was edited by:

KayDeE

KayDeEa at 2007-7-8 22:35:40 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...