I am using mysql as database and netbeans as IDE ..
I tried this small code to get database connectivity
[code=java
package database;
/**
*
* @author midhun
*/
import java.sql.*;
public class JDBCSAMPLE {
public static void main( String args[]) {
String connectionURL = "jdbc:mysql://localhost:3306/cmgmt";
// Change the connection string according to your db, ip, username and password
try {
// Load the Driver class.
Class.forName("com.mysql.jdbc.Drive");
// If you are using any other database then load the right driver here.
//Create the connection using the static getConnection method
Connection con = DriverManager.getConnection (connectionURL);
//Create a Statement class to execute the SQL statement
Statement stmt = con.createStatement();
//Execute the SQL statement and get the results in a Resultset
ResultSet rs = stmt.executeQuery("select * from regist;");
// Iterate through the ResultSet, displaying two values
// for each row using the getString method
while (rs.next())
System.out.println("Name= " + rs.getString("f_n") + " sex= " + rs.getString("sex")+"place="+rs.getString("place"));
}
catch (SQLException e) {
e.printStackTrace();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
][/code]
But i am getting the error when i run the fie error is
init:
deps-module-jar:
deps-ear-jar:
deps-jar:
compile-single:
run-main:
java.lang.ClassNotFoundException: com.mysql.jdbc.Drive
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:186)
at database.JDBCSAMPLE.main(JDBCSAMPLE.java:25)
BUILD SUCCESSFUL (total time: 2 seconds)
Any guess how to solve this problem..