此代码没有错误或异常,但在运行数据库中的表features
后仍为空
try {
Class.forName("com.mysql.jdbc.Driver");
con= (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/sounds","root","");
statment = (Statement) con.createStatement();
String query = "INSERT INTO featuers (avg_Bandwidth) values (?)";
PreparedStatement preparedStmt = (PreparedStatement)con.prepareStatement(query);
preparedStmt.setDouble(1, avarage_Bandwidth);
preparedStmt.executeUpdate();
con.close();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
答案 0 :(得分:1)
有两点值得注意:
statment = (Statement) con.createStatement();
preparedStmt.executeUpdate();
答案 1 :(得分:1)
你好试着用这个。
int status = 0; // to get the status to know if statement is executed properly or not
try {
Connection con = DBConnection.getConnect();//Your database Connection
Statement st = con.createStatement();
status = st.executeUpdate(query); //After executing this it will return an int value
} catch (Exception ex) {
ex.printStackTrace();
}
我希望这会对你有所帮助。