Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Deleting from a MS Access Database  RSS feed

 
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
 
Marshal
Posts: 60116
188
  • 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.
 
Sheriff
Posts: 23702
50
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:
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!