dcsimg
INSERT statement wont execute
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Patrick_Hutchinson
Posted On:   Tuesday, November 5, 2002 07:58 AM

I'm trying to execute an INSERT statement for a MS Access database and I am getting a strange exception. I know the connection is fine because I can query the database fine just not insert. if I try something like this stmt.executeUpdate("INSERT INTO Employee VALUES ("John Smith")"); it works fine but if I try String name = "John Smith"; stmt.executeUpdate("INSERT INTO Employee VALUES (name)"); the program throws the Exception java.sql.SQLException[Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1 Am I missing something here? I am using the sun   More>>

I'm trying to execute an INSERT statement for a MS Access database and I am getting a strange exception. I know the connection is fine because I can query the database fine just not insert. if I try something like this


stmt.executeUpdate("INSERT INTO Employee VALUES ("John Smith")");


it works fine but if I try


String name = "John Smith";

stmt.executeUpdate("INSERT INTO Employee VALUES (name)");

the program throws the Exception

java.sql.SQLException[Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1


Am I missing something here?


I am using the sun ODBC-JDBC driver.


Please use html tags to format code blocks.

   <<Less

Re: INSERT statement wont execute

Posted By:   Simon_Ablett  
Posted On:   Tuesday, November 5, 2002 08:03 AM

Change..

String name = "John Smith";
stmt.executeUpdate("INSERT INTO Employee VALUES (name)");

To...

String name = "John Smith";
stmt.executeUpdate("INSERT INTO Employee VALUES ('"+name+"')");

Regards
About | Sitemap | Contact