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....

  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

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.

Its working..Thank You soo much.

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.

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>

@soumali12345 what a splendid idea to mix ASP with JSP

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.