aspose file tools
The moose likes JDBC and Relational Databases and the fly likes is this SQL Stament correct ??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA Java SE 8 Programmer I Study Guide 1Z0-808 this week in the OCAJP forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "is this SQL Stament correct ???" Watch "is this SQL Stament correct ???" New topic
Author

is this SQL Stament correct ???

vikas de
Ranch Hand

Joined: Feb 07, 2001
Posts: 39
String table="tableName";
String tableValue="12";
int result=stmt.executeUpdate(Insert into '"+table+"' values('"+tableValue+"')");
is this statement correct !!!???

[This message has been edited by vikas de (edited March 30, 2001).]
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
It will be almost correct if your table only has a single column of a text type. You should remove the quotes from the table name, first, though. As with "select" statements, it's almost always better to specify the column names:
int result = stmt.executeUpdate("insert into " + table + " (colname) values('" + tableValue + "')" );
If your column has a numeric type, you should not put quotes on the value either:
int result = stmt.executeUpdate("insert into " + table + " (colname) values(" + tableValue + ")" );


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
vikas de
Ranch Hand

Joined: Feb 07, 2001
Posts: 39
Thanx a lot...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: is this SQL Stament correct ???