This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting Problem In updating or deleting data in MS Access Database

 
Preetish Madalia
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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(
"jdbcdbcriver={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 = "jdbcdbcriver={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. But, the problem is that the data in the table is not getting deleted.
Are there settings we need to make in order to delete/update data in tables.
Pls. look at my problem.
Thanks in advance.

Regards,
Preetish.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic