File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Deleting from a MS Access Database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Deleting from a MS Access Database" Watch "Deleting from a MS Access Database" New topic
Author

Deleting from a MS Access Database

Femi Ojambati
Greenhorn

Joined: Aug 13, 2008
Posts: 6
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

Joined: Oct 13, 2005
Posts: 38818
    
  23
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
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

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:
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Deleting from a MS Access Database