Two Laptop Bag*
The moose likes JDBC and the fly likes problem with MS Access and max Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "problem with MS Access and max" Watch "problem with MS Access and max" New topic
Author

problem with MS Access and max

Aris Doxakis
Ranch Hand

Joined: Dec 05, 2004
Posts: 136

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.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30123
    
150

Aris,
Can you show a little more code? In particular the code that actually runs the insert statement.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Wei Dai
Ranch Hand

Joined: Jun 22, 2005
Posts: 86
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

Joined: Dec 05, 2004
Posts: 136

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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30123
    
150

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

Joined: Dec 05, 2004
Posts: 136

sorry didn't mention it Cidd is a integer.Not a string.
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1321

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 ]

Saifuddin..
[Blog][Linkedin] How To Ask Questions On JavaRanch My OpenSource
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem with MS Access and max
 
Similar Threads
javabean problem
How to use Sequence using sql commands
request.parameter
Servlet help
javabean problem