Guys, i am not able to update/delete data from in a table in MS Access Database.
import java.sql.Connection;
import java.util.Date;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Time;
import java.util.Calendar;
public class JdbcConnection {
public static final
String INSERT_QUERY =
"insert into USER_SUMMARY(user_id,login_time,login_date,LOGIN_STATUS) values(?,?,?,?)";
public static final String SELECT_QUERY =
"select * from user_summary";
public static final String FIND_USER=
"select user_id from user_summary where login_status = 'Y'";
public static final String DELETE_USER_STATUS =
"DELETE user_summary.* FROM user_summary where user_id=?";
public static void main(String[] args) {
try {
Driver d = (Driver)Class.forName
("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
Connection conn = DriverManager.getConnection(
"jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=E:/DATABASE/Database3.mdb"
);
/*System.out.println("Begining conn");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String filename = "E:/DATABASE/Database1.mdb";
String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=";
database+= filename.trim() + ";PWD=test}";
Connection conn = DriverManager.getConnection( database ,"Preetish_Madalia","preetish"); */
System.out.println("Connection Obtained : " + conn );
PreparedStatement ps3 = conn.prepareStatement(DELETE_USER_STATUS);
ps3.setInt(1,1);
int result2 = ps3.executeUpdate();
System.out.println(result2);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch(SQLException sqe){
sqe.printStackTrace();
System.out.println(sqe);
} catch(Exception e){
e.printStackTrace();
}
}
}
The above code runs fine.. also the value of executeUpdate() comes out to be one(i.e. one row is to be deleted) . However, the data is not getting deleted from the table.
Is there any setting we need to set in order to allow the deletion/updation of data in the database when we fire a query from our program.
Pls. look into this problem.