954,574 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Inserting data through JSP

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

gsd
Newbie Poster
2 posts since Sep 2009
Reputation Points: 10
Solved Threads: 0
 
  • Please use full sentence English, chat speak is not welcome
  • If you do database connection through JSP then that is bad
  • your SQL query is malformed
  • have look on the post on the top of JSP section for general idea about querying database
peter_budo
Code tags enforcer
Moderator
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
 

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.

joewazen
Newbie Poster
17 posts since Jun 2008
Reputation Points: 33
Solved Threads: 0
 

Its working..Thank You soo much.

gsd
Newbie Poster
2 posts since Sep 2009
Reputation Points: 10
Solved Threads: 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.

joewazen
Newbie Poster
17 posts since Jun 2008
Reputation Points: 33
Solved Threads: 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/

soumali12345
Newbie Poster
1 post since Sep 2009
Reputation Points: 10
Solved Threads: 0
 

@soumali12345 what a splendid idea to mix ASP with JSP

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

peter_budo
Code tags enforcer
Moderator
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You