• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Deleting from a MS Access Database

 
Femi Ojambati
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please, I have a problem with deleting a row from in a table in a database.
This is my code:

public class CooperativeDB{

String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
String host = "jdbcdbc:CTCS Database";
Connection conn = null;
public static void main(String [] args){
try{
Class.forName (driver);
conn = DriverManager.getConnection(host, "", "");
conn.setAutoCommit(true);
stat = conn.createStatement();

String stringUpdate = "DELETE FROM Loan WHERE Member_ID_No = ?"
PreparedStatement ps = conn.prepareStatement(stringUpdate);
ps.setInt(1,2);
ps.executeUpdate();
conn.close();
}catch(Exception e){
System.out.print(e.getStackTrace());
System.out.print(e);
}
}
}
When I ran it, this messages were displayed:
[Ljava.lang.StackTraceElement;@1389e4 java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 2.

Please, help me check the code
 
Campbell Ritchie
Sheriff
Pie
Posts: 50175
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't know. I don't think the Exception is occurring where you think it is. Please check the stack trace for line numbers and where the Exception is occurring. Use exc.printStackTrace(), not getStackTrace().

Please use the code button; your code is difficult to read. And please post real code; I can see a compiler error in what you have posted at a � minute look.
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That message typically occurs in Access when you use a table name which isn't in the database you are connected to, and when you use a column name which isn't in the table you are using.

So that would mean you misspelled the table name or the column name. Or you connected to the wrong database.

By the way the standard way of printing the stack trace is this:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic