Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
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 Murach's Java Servlets and JSP this week in the Servlets 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...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: is this SQL Stament correct ???
 
Similar Threads
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
Having problem in resetting the value of JTable