public void btnInsert_actionPerformed(ActionEvent e) {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (ClassNotFoundException ex) {
System.out.println("错误1");
}
try {
String str = "jdbc:odbc:test";
Connection con = DriverManager.getConnection(str);
if(txtClass.getText().trim().length()==0){
JOptionPane.showMessageDialog(this,"请填写班级号!","错误",JOptionPane.INFORMATION_MESSAGE);
return;
}
if(txtTotal.getText().trim().length()==0){
JOptionPane.showMessageDialog(this,"请填写考试人数!","错误",JOptionPane.INFORMATION_MESSAGE);
return;
}
if(txtPass.getText().trim().length()==0){
JOptionPane.showMessageDialog(this,"请填写通过人数!","错误",JOptionPane.INFORMATION_MESSAGE);
return;
}else{
PreparedStatement ps=con.prepareStatement("insert into passratio (class_id,total,pass,ratio) values (?,?,?,?)");
ps.setInt(2,Integer.parseInt(txtClass.getText().trim()));
ps.setInt(3,Integer.parseInt(txtTotal.getText().trim()));
ps.setInt(4,Integer.parseInt(txtPass.getText().trim()));
float a=Float.parseFloat(txtPass.getText().trim());
float b=Float.parseFloat(txtTotal.getText().trim());
ps.setFloat(5,a/b);
ps.executeUpdate();
ps.close();
con.close();
JOptionPane.showMessageDialog(this,"插入记录成功!","消息",JOptionPane.INFORMATION_MESSAGE);
}
} catch (SQLException ex1) {
System.out.println("错误2");
}
}
}
数据源test 表名passratio 列名id int 标识列
class_id int 主键
total int
pass int
ratio float
貌似是float那块错了。。。请帮我看看,谢谢