I have problem to connect to my Database from my Java Code. I am using MS Access Database. I have created DSR Name and selected appropriate Database for my DSR Name.
DSR Name : connectionExample
Operating System : Windows 8 Pro (64 Bit).
Please answer me with full tutorial because I am a newbie.
My Java Code for Database Connection Example is :
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
public class DatabaseConnection {
public static void main(String[] args) {
String uName="ABC",uPass="ABC",uEmail="ABC",uDate="ABC",uContactNo="ABC";
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Driver Loaded");
Connection con = DriverManager.getConnection("Jdbc:odbc:connectionExample");
Statement stmnt = con.createStatement();
String sql = "insert into UserDetail values ('"+uName + "','"+uPass+"','"+uEmail+"','"+uDate+"','"+uContactNo+"')";
int cnt = stmnt.executeUpdate(sql);
System.out.println("Database Updated.");
}
catch (Exception ex)
{
System.out.println(ex);
}
}
}
The Output of my code is :
run:
java.lang.ClassNotFoundException: sun.jdbc.odbc.JdbcOdbcDriver
BUILD SUCCESSFUL (total time: 0 seconds)