-1

这是查询

 String query = 
 "SELECT idPlayers 
 FROM pendu.players 
 WHERE first= 'Super'AND last='Man' AND pass=12345";

我想将 (first='Super') 更改为 first = tboxFirst.getText() 等

谢谢你帮助我

坦率

4

4 回答 4

4

如果您使用的是字符串,则可以像这样创建带有值的字符串:

 String query = "SELECT idPlayers FROM pendu.players WHERE first= '" + tboxFirst.getText() + "'AND last='Man' AND pass=12345";

您还应该看一下,PreparedStatement因为这是一个更好的解决方案。

于 2012-04-16T00:27:51.100 回答
2
  PreparedStatement pstmt = con.prepareStatement(
  "SELECT idPlayers FROM pendu.players WHERE 
       first= ? AND last= ? AND pass=?");

   pstmt.setString(1, tboxFirst.getText());
   pstmt.setString(2, ....);
   ....
于 2012-04-16T00:33:52.417 回答
0

String query = "SELECT idPlayers FROM pendu.players WHERE first=('"+tboxFirst.getText()+"') AND pass=12345";

于 2012-04-16T00:31:42.153 回答
0

你可以使用
String query = "SELECT idPlayers FROM pendu.players WHERE first='"+tboxFirst.getText()+"'AND last='Man' AND pass=12345";

或者

String query = String.format(SELECT idPlayers FROM pendu.players WHERE first='%s'AND last='Man' AND pass=12345", tboxFirst.getText());

如果你使用 JDBC,你可以使用 PreparedStatement
PreparedStatement pstmt = con.prepareStatement("SELECT idPlayers FROM pendu.players WHERE first=? AND last=? AND pass=?");
pstmt.setString(1, "Super");
pstmt.setString(2, "Man");
pstmt.setString(3, "12345");

于 2012-04-16T01:06:34.677 回答