This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JDBC 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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
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...
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: is this SQL Stament correct ???
 
Similar Threads
Having problem in resetting the value of JTable
How to set focus on submit button on press of enter key
searching a row using text fields
HOW MANY OBJECTS ARE CREATED
Precedence table