我正在使用连接到WAMPServer提供的MySQL数据库的模拟器。
一切都已连接,但显示的值(使用println)和数据库不匹配。
数据库中的值只记录0,但假设的值是3127.帮帮我?
public void addTotal(String total){
this.totaltxt.setText(total);
totalVal = Integer.parseInt(this.totaltxt.getText());
}
public void actionPerformed(ActionEvent evt){
if(evt.getSource()==enter){
main.removeAll();
main.repaint();
action.createSim();
action.startSim();
db.saveVAL(0,totalVal);
System.out.println(totalVal);
}
}
数据库:
public void saveVAL(int sim_time, int sim_total){
try{
Statement stmt = conn.createStatement();
stmt.executeUpdate("INSERT INTO sim_energy (sim_time, sim_total) VALUES ("+sim_time+","+sim_total+")");
System.out.println("Adding was successful");
}catch (Exception ex){
System.out.println("Inserting values unsuccessful");
//ex.printStackTrace();
}
}