1

我 12 岁,我正在学习导致一些问题的 java:D。因为我不能真正编程那么多所以这是我的问题。我想用 Java 编辑一个数据库,我的数据库服务器在 Wamp 上运行,所以我有 PhpMySql 。我创建了一个数据库并试图让它在 Java 中显示得很好,现在我想通过 java 编辑数据库。我认为这段代码可能有效:

rs = stmt.executeQuery("UPDATE  `martbank`.`users` SET  `Balance` =  
  '"+Saldo.getText()+"' WHERE  `users`.`User_Id` ="
            +Nummer.getText()
            +" AND  `users`.`Surname` =  '"+lastname.getText()
            +"' AND  `users`.`Firstname` =  '"+firstname.getText()
            +"' AND  `users`.`Pin` = '"+Password.getText()
            +"' AND  `users`.`Balance` = '"+Saldo.getText()
            +"' AND  `users`.`Password` =  '"+Password.getText()+"' LIMIT 1 ;");

如果我能得到帮助,我很高兴听到这件事。

4

1 回答 1

0

Your question is - sorry to say - very unspecific, but let me try to give you a little insight.

First, you should get familiar with JDBC and the concept of connecting to a database and executing queries. The Oracle Learing Trail on this is a perfect start. It will give you simple out-of-the-box examples on how to use a JDBC driver, connect and how to use a database connection.

After that, make sure that you know what a PreparedStatement is and how to use it. The way you're composing queries allows SQL injection attacs much too easy.

Hope this answer empowers you to get in touch with Java and Databases.

于 2013-03-20T07:08:23.273 回答