Hi
This is my codings in order to access mysql database from java.
Codings:
import java.sql.Connec tion;
import java.sql.Driver Manager;
import java.sql.Result Set;
import java.sql.Statem ent;
public class MysqlConnect {
public static void main(String[] args)throws Exception{
System.out.prin tln("MySQL Connect Example.");
Connection conn = null;
String url = "jdbc:mysql ://localhost:3309/";
String dbName = "ananthu";
String driver = "com.mysql.jdbc .Driver";
String userName = "root";
String password = "sa";
try {
Class.forName(d river);
conn = DriverManager.g etConnection(ur l+dbName,userNa me,password);
System.out.prin tln();
System.out.prin tln("Connected to the database");
System.out.prin tln();
Statement stmt = conn.createStat ement();
ResultSet reset = stmt.executeQue ry("select * from customer");
System.out.prin tln("Name\t\tAg e");
System.out.prin tln();
while(reset.nex t()){
//System.out.prin tln(reset.getSt ring(1));
//System.out.prin tln(reset.getSt ring(2));
System.out.prin tln(reset.getSt ring(1)+ "\t\t" + reset.getString (2));
}
conn.close();
System.out.prin tln();
System.out.prin tln("Disconnect ed from database");
} catch (java.lang.Clas sNotFoundExcept ion e) {
e.printStackTra ce();
}
}
}
I have mysqlconnector 5.0.7 jar file and i have placed it in program files folder.
The following is the execution of my codings.
Execution:
c:\program~1\ja va\jdk1.6.0_01\ bin>javac -classpath ";.\program files\mysql-connector-java-5.6.0_01" mysqlconnect
c:\progra~1\jav a\jdk1.6.0_01\b in>java -classpath ";.\program files\mysql-connector-java-5.6.0_01" mysqlconnect
Exception in thread "main" java.lang.nocla ssdeffound error: mysqlconnect
-----
The above error occurs only during running the program and not in compilation time.
How to rectify the error and run the program successfully?
Please help me...
This is my codings in order to access mysql database from java.
Codings:
import java.sql.Connec tion;
import java.sql.Driver Manager;
import java.sql.Result Set;
import java.sql.Statem ent;
public class MysqlConnect {
public static void main(String[] args)throws Exception{
System.out.prin tln("MySQL Connect Example.");
Connection conn = null;
String url = "jdbc:mysql ://localhost:3309/";
String dbName = "ananthu";
String driver = "com.mysql.jdbc .Driver";
String userName = "root";
String password = "sa";
try {
Class.forName(d river);
conn = DriverManager.g etConnection(ur l+dbName,userNa me,password);
System.out.prin tln();
System.out.prin tln("Connected to the database");
System.out.prin tln();
Statement stmt = conn.createStat ement();
ResultSet reset = stmt.executeQue ry("select * from customer");
System.out.prin tln("Name\t\tAg e");
System.out.prin tln();
while(reset.nex t()){
//System.out.prin tln(reset.getSt ring(1));
//System.out.prin tln(reset.getSt ring(2));
System.out.prin tln(reset.getSt ring(1)+ "\t\t" + reset.getString (2));
}
conn.close();
System.out.prin tln();
System.out.prin tln("Disconnect ed from database");
} catch (java.lang.Clas sNotFoundExcept ion e) {
e.printStackTra ce();
}
}
}
I have mysqlconnector 5.0.7 jar file and i have placed it in program files folder.
The following is the execution of my codings.
Execution:
c:\program~1\ja va\jdk1.6.0_01\ bin>javac -classpath ";.\program files\mysql-connector-java-5.6.0_01" mysqlconnect
c:\progra~1\jav a\jdk1.6.0_01\b in>java -classpath ";.\program files\mysql-connector-java-5.6.0_01" mysqlconnect
Exception in thread "main" java.lang.nocla ssdeffound error: mysqlconnect
-----
The above error occurs only during running the program and not in compilation time.
How to rectify the error and run the program successfully?
Please help me...
Comment