I have my java application and try to connect with mysql database.But i can't able to get the output,i am getting the Exception error.I think i am not able to connect with the driver.My OS is Linux(Ubuntu).
nikki@nikki-laptop:~$ java -version
java version "1.6.0_20"
OpenJDK Runtime Environment (IcedTea6 1.9) (6b20-1.9-0ubuntu1)
OpenJDK Client VM (build 17.0-b16, mixed mode, sharing)
nikki@nikki-laptop:~$ echo $JAVA_HOME
/usr/java/jdk1.6.0_20/bin/java
nikki@nikki-laptop:~$ echo $CLASSPATH
.:/usr/share/java/mysql.jar:/home/nikki/temp/src/jclass
My jdk path is /usr/lib/jvm/java-1.6.0-openjdk/jre
My Java program is
import java.sql.*;
class Query1
{
public static void main(String args[])throws Exception
{
try
{ // the mysql driver string
Class.forName("com.mysql.jdbc.Driver").newInstance ();
// the mysql url = "jdbc:mysql://THE_HOST/THE_DATABASE";
//String url = "sun.jdbc.odbc.JdbcOdbcDriver";
String url ="jdbc:mysql://localhost/mylib_db";
Connection conn = DriverManager.getConnection(url,"nikki","dkm007");
Statement stmt = conn.createStatement();
//ResultSet rs;
ResultSet rs = stmt.executeQuery("select title from Book_dim where cost=435.89");
while (rs.next())
{
String titlename = rs.getString("title");
System.out.println(titlename + "\n");
}
conn.close();
}
catch(Exception e)
{
System.err.println("Got an exception! ");
System.err.println(e.getMessage());
}
}
}
My output is
- - - - -
nikki@nikki-laptop:~/Documents/Chinu/mydbP$ javac Query1.java
nikki@nikki-laptop:~/Documents/Chinu/mydbP$ java Query1
Got an exception!
com.mysql.jdbc.Driver
I didn't added any driver...i don't know which Driver should i use .How can i add driver? If possible plz send me the reply.