Greetings there,
i was trying to connect to mySql using jdbc...
i have downloaded and set classpath for the
mysql-connector/J JAR file.. but still i am getting
the following exception...
<code>
import java.sql.*;
public class Connect
{
public static void main (String[] args)
{
Connection conn = null;
try
{
String userName = "testuser";
String password = "testpass";
String url =
"jdbc:mysql://localhost/test";
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");
e.printStackTrace();
}
finally
{
if (conn != null)
{
try
{
conn.close ();
System.out.println ("Database
connection terminated");
}
catch (Exception e) { /* ignore
close errors */ }
}
}
}
}
</code>
<output>
[EMAIL PROTECTED] Java]$ javac Connect.java
[EMAIL PROTECTED] Java]$ java Connect
Cannot connect to database server
java.lang.ClassNotFoundException:
com.mysql.jdbc.Driver
at
java.net.URLClassLoader$1.run(URLClassLoader.java:199)
at
java.security.AccessController.doPrivileged(Native
Method)
at
java.net.URLClassLoader.findClass(URLClassLoader.java:187)
at
java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
at
java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at
java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:141)
at Connect.main(Connect.java:14)
[EMAIL PROTECTED] Java]$ set | grep CLASSPATH
CLASSPATH=/home/rohitsz/software/mysql-connector-java-3.1.11/:.
[EMAIL PROTECTED] Java]$
[EMAIL PROTECTED] Java]$ ls
/home/rohitsz/software/mysql-connector-java-3.1.11
build.xml COPYING docs/
mysql-connector-java-3.1.11-bin.jar README.txt
CHANGES debug/ EXCEPTIONS-CONNECTOR-J README
src/
[EMAIL PROTECTED] Java]$
</output>
i have set class path as directed in the mysql
tutorials but still am unable to connect..
kindly suggest what i am doing wrong OR am i missing
some plugin still..
thanks,
rohit.
NAMASTE, i honour the spirit in you which is also in me.
```````````````````````````````````````````````````````
http://www.geocities.com/rohitsz2
__________________________________
Yahoo! Mail - PC Magazine Editors' Choice 2005
http://mail.yahoo.com
_______________________________________________
Java mailing list
[email protected]
http://mail.jug-delhi.org/mailman/listinfo/java_jug-delhi.org