Monday, 19 September 2011

how to connect with jdbc,odbc with access


import java.sql.*;
public class Test1
{
 public static void main(String[] args)
 {
 try {
int rollno=240;
String name="Tahir";
String address="Lahore";
String course="Java";

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:StudentDB");
Statement s = con.createStatement();
s.executeUpdate("insert into StudentTable(RollNo,StudentName,StudentAddress,StudentCourse)

values("+rollno+",'"+name+"','"+address+"','"+course+"')");


s.close();
con.close();   }
catch (Exception err) {
System.out.println("ERROR: " + err);
 }
 }
}    

No comments:

Post a Comment