1
爲什麼預準備語句不會將數據插入數據庫表中?JDBC Java準備語句執行錯誤
import java.sql.*;
public class MysqlConnect{
public static void main(String[] args) {
System.out.println("MySQL Connect Example.");
Connection conn = null;
String url = "jdbc:mysql://localhost/";
String dbName = "java";
String driver = "com.mysql.jdbc.Driver";
String userName = "root";
String password = "";
PreparedStatement pst;
try {
Class.forName(driver).newInstance();
conn = DriverManager.getConnection(url+dbName,userName,password);
conn.setAutoCommit(false);
String sql = "INSERT INTO test (url) values(?)";
PreparedStatement statement = conn.prepareStatement(sql);
statement.setString(1, "teast.com");
statement.executeUpdate();
statement.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
你會得到什麼錯誤信息? – vextorspace 2012-02-01 18:19:21