• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

problem with MS Access and max

 
Ranch Hand
Posts: 136
Android Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello fellow ranchers,
im trying to make a online bookstore work usin jsp and my database is created in MS Access 2003.Dont ask why but thats were i was told to fix the database.Anyway,im trying to insert a new customer in my register form but nothing gets inserted in my database.Here is the code for finding the max id:
Statement stmt3 = con.createStatement();
ResultSet rs1 = stmt3.executeQuery("select Max(Customer_ID) from Customers;");
int maxID = Integer.parseInt(rs1.getString("Customer_ID")) + 1;
and here is my insert statement:
Statement stmt1 = con.createStatement();
String insertCustomer = "Insert into Customers (Customer_ID,CreditCard_ID,FirstName,LastName,E_Mail,Address,ZipCode,City,Telephone,MoreHelp) " +
"Values(" + maxID + "," + maxID + ",'" + FName + "','" + LName + "','" + Email + "','" + Address + "','" + ZipCode + "','" + City + "','" + Telephone + "','" + MoreHelp +"');";

if anyone could help ill be grateful.
thnx in advance.
 
author & internet detective
Posts: 41919
910
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Aris,
Can you show a little more code? In particular the code that actually runs the insert statement.
 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It should be resulted by a bug for MS Access ODBC driver, you can try:
con.commit(); con.close(); then you should see your inserted row.

Another solution is to use a commercial JDBC driver for MS Access at http://www.hxtt.com/access.html .
 
Aris Doxakis
Ranch Hand
Posts: 136
Android Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thnx found out what was the problem.Microsoft they say:).
ok so this works and now i have a new problem.i get the customerid from one page to another but when i use it in an sql query i get an error :
Too few parameters. Expected 1.
my code that makes this error is :
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select * from Customers where Customer_ID = Cidd;");
 
Jeanne Boyarsky
author & internet detective
Posts: 41919
910
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Aris,
Most databases require quotes around a string value. Have you tried the following?

select * from Customers where Customer_ID = 'Cidd';
 
Aris Doxakis
Ranch Hand
Posts: 136
Android Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry didn't mention it Cidd is a integer.Not a string.
 
Ranch Hand
Posts: 1325
Android Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Aris Doxakis:
ResultSet rs = stmt.executeQuery("select * from Customers where Customer_ID = Cidd;");



Cidd is a variable of int type and I think "Cidd" is not a value inside your Customer_ID field.

just use concatenate by + sign to comparing the value of its int type variable
[ August 26, 2006: Message edited by: Saif Uddin ]
 
knowledge is the difference between drudgery and strategic action -- tiny ad
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic