我在网上找到了一个示例后编写了此代码,但它不起作用,请您告诉我它可能有什么问题。它似乎在做某事并打印出结果,但没有任何变化。
package com.company.Start;
import java.sql.*;
public class PreparedStmt
{
public static void main(String[] args) throws Exception
{
Class.forName("oracle.jdbc.OracleDriver");
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@PC:1521/XE","ACCOUNT", "password");
PreparedStatement updateDB = con.prepareStatement("UPDATE Customers SET lname=? WHERE name=?");
updateDB.setString(1, "Meier");
updateDB.setString(2, "Peter");
updateDB.execute();
Statement smt = con.createStatement();
String query = "SELECT * FROM customers";
ResultSet rs = smt.executeQuery(query);
System.out.println("NAME LNAME ADRESS");
while (rs.next()) {
String name = rs.getString("name");
String lname = rs.getString("lname");
System.out.println(name + " " + lname);
}
}
}