• Post Reply Bookmark Topic Watch Topic
  • New Topic

help with a statement

 
ben riches
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello i hope someone can help me please
i have this statement below.
PreparedStatement pstmt = conn.prepareStatement("INSERT INTO Cust VALUES (?, ?)");
what i want to do is get the name of the table from JTextField 1 how would i do this?
 
Braj Prasad
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use the following :-
String lStrTableName = JTextField.getText();
PreparedStatement pstmt = conn.prepareStatement("INSERT INTO " + lStrTableName + " VALUES (?, ?)");
pstmt.setString(1, Str1);//assuming a varchar column
pStmt.setString(2, Str2);
 
Let's get him boys! We'll make him read this tiny ad!
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!