0
使用netbeans和mysql我創建了一個表,我希望用戶能夠使用java向它添加數據。有人可以舉例說明如何將新客戶名稱添加到具有字段名稱的表名客戶端。Netbeans mysql表
這會自動把它,但我需要的用戶名添加到表
public static void insertClients() throws SQLException {
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
} catch (Exception E) {
System.err.println("Unable to load driver.");
E.printStackTrace();
}
try {
Connection con = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/clients","root","pass");
con.setAutoCommit(false);
Statement statement = con.createStatement();
String newClient = "insert into client values(John);";
statement.executeUpdate(newName);
System.out.println("Client added");
con.commit();
con.close();
你需要引用你的名字,並命名你插入的列。但更好地使用*準備好的語句*。 –