public void actionPerformed(ActionEvent a){
String s,store2,pro2,price2,quantity2,total2;
s=a.getActionCommand();
String store,pro,price,quantity,total;
double i3,i4,i5;
if(s.equals("出售")){
try{
SimpleDateFormat d=new SimpleDateFormat("yyyy.MM.dd hh:mm:ss");
String date=d.format(new Date());
store=new String(tf1.getText().getBytes(),"ISO8859_1");
pro=new String(tf2.getText().getBytes(),"ISO8859_1");
price=tf3.getText();
quantity=tf4.getText();
i3=Double.parseDouble(price);
i4=Double.parseDouble(quantity);
i5=i3*i4;
total=Double.toString(i5);
tf5.setText(""+total);
Class.forName("org.gjt.mm.mysql.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/myjava", "root", "sa");
Statement stmt=con.createStatement();
stmt.executeUpdate("insert into sale values('"+store+"','"+pro+"',"+price+","+quantity+","+total+","+date+");");
lb6.setText("成功出售");
con.close();
}
catch(Exception e){
System.out.println("connect fail");
}
}//部分代码,当去掉date数据时,就可以成功插入数据库,请高手帮我看看,是不是我的SQL语句有问题,还是怎么了
String s,store2,pro2,price2,quantity2,total2;
s=a.getActionCommand();
String store,pro,price,quantity,total;
double i3,i4,i5;
if(s.equals("出售")){
try{
SimpleDateFormat d=new SimpleDateFormat("yyyy.MM.dd hh:mm:ss");
String date=d.format(new Date());
store=new String(tf1.getText().getBytes(),"ISO8859_1");
pro=new String(tf2.getText().getBytes(),"ISO8859_1");
price=tf3.getText();
quantity=tf4.getText();
i3=Double.parseDouble(price);
i4=Double.parseDouble(quantity);
i5=i3*i4;
total=Double.toString(i5);
tf5.setText(""+total);
Class.forName("org.gjt.mm.mysql.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/myjava", "root", "sa");
Statement stmt=con.createStatement();
stmt.executeUpdate("insert into sale values('"+store+"','"+pro+"',"+price+","+quantity+","+total+","+date+");");
lb6.setText("成功出售");
con.close();
}
catch(Exception e){
System.out.println("connect fail");
}
}//部分代码,当去掉date数据时,就可以成功插入数据库,请高手帮我看看,是不是我的SQL语句有问题,还是怎么了
util 支持 时、分、秒,sql包不支持