0

Hii frnds,
I want to know how to insert data into a table through JSP when u have the table name as a variable...Pls help me out.

Statement stmt5=con.createStatement();
      String qry5="insert into t1(id) values('"+dat0+"')"; 
      int u5=stmt5.executeUpdate(qry5);

I know this stuff. Wat I want to know is how do we do it if I had some String tname="t1". I want to use the insert command using tname and not t1.

Ive tried this: insert into '"+tname+"' values(____); But ti dint work...Plz plz help me out....

Edited by peter_budo: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.

4
Contributors
6
Replies
7
Views
8 Years
Discussion Span
Last Post by peter_budo
0
  1. Please use full sentence English, chat speak is not welcome
  2. If you do database connection through JSP then that is bad
  3. your SQL query is malformed
  4. have look on the post on the top of JSP section for general idea about querying database
0

String DataEntry_TableName = "t1";

query = "insert into "+DataEntry_TableName+" (NameA) values ('"+NameA+"')";

if this didn't work then print the exception and post it please.

Edited by peter_budo: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.

0

your welcome. the problem was with the table name with using '"+tablename+"' instead of "+tablename+" which made the insert statement insert into 'tablename' instead insert into tablename. please post it as solved.

0

Hii frnds,
I want to know how to insert data into a table through JSP when u have the table name as a variable...Pls help me out.

Statement stmt5=con.createStatement();
String qry5="insert into t1(id) values('"+dat0+"')";
int u5=stmt5.executeUpdate(qry5);

I know this stuff. Wat I want to know is how do we do it if I had some String tname="t1". I want to use the insert command using tname and not t1.

Ive tried this: insert into '"+tname+"' values(____);
But ti dint work...Plz plz help me out....

this tutorial ma help u
http://www.vclcomponents.com/ASP/Tips_and_Tutorials/Database_Management/

<FAKE SIGNATURE>

Edited by peter_budo: Keep It On The Site - Do not manually post &quot;fake&quot; signatures in your posts.

0

@soumali12345 what a splendid idea to mix ASP with JSP

PS: that link is not leading to tutorial but some general search result

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.