import java.sql.*;
public class NewConnection{ private static Connection con;
private static ResultSet rs;
private static Statement sm;
private static final String DRIVER = "sun.jdbc.odbc.JdbcOdbcDriver";
private static final String URL = "jdbc:odbc:Driver={Microsoft Access driver (*.mdb)};DBQ=E:\\Database.mdb;";
private static String query;
int i;
private void getConnection(){
try {
Class.forName(DRIVER);
System.out.println("Driver Connected");
con=DriverManager.getConnection(URL);
System.out.println("Database Connected");
sm=con.createStatement();
} catch (Exception e) {
}
}
private int ExecuteUpdate(String query1)
{
try {
System.out.println(query1);
i=sm.executeUpdate(query1);
} catch (Exception e) {
e.printStackTrace();
}
return i;
}
public static void main(String []args){
NewConnection n= new NewConnection();
n.getConnection();
query="insert into Emp values('samr','sam','sa','aas')";
System.out.println(n.ExecuteUpdate(query));
}
}
This is the code for inserting the data in d MS Access Database.Databse is the name of d database. But i m not able to insert the data in it.The query runs successfully but doesn't add data in database. Don't know y..? The code creats the table in database successfully if query changed.
Can any one tell me what is the problem Or Where i m wrong..
Thank you