ODBC配置应该是没问题,可为什么调试了好几次都是连接不上数据库
if(s.equals("出售")){
try{
SimpleDateFormat d=new SimpleDateFormat("yyyyMMddhhmmss");
String no=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("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jbdc:odbc:MyOdbc","","");
Statement stmt=con.createStatement();
stmt.executeUpdate("insert into [Sheet1$] values('"+no+"','"+store+"','"+pro+"',"+price+","+quantity+","+total+");");
lb6.setText("成功出售");
con.close();
}
catch(Exception e){
System.out.println("connect fail");
}
}
else if(s.equals("所有销售记录")){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jbdc:odbc:MyOdbc","","");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from [Sheet1$];");
while(rs.next()){
String st1,st2;
st1=new String(rs.getString(2).getBytes("ISO8859_1"));
st2=new String(rs.getString(3).getBytes("ISO8859_1"));
System.out.print("编号:"+rs.getString(1)+" ");
System.out.print("连锁店:"+st1+" ");
System.out.print("商品:"+st2+" ");
System.out.print("单价:"+rs.getString(4)+" ");
System.out.print("数量:"+rs.getString(5)+" ");
System.out.println("总价:"+rs.getString(6));
}
con.close();
}
catch(Exception e){
System.out.print("查询失败");
}
}//部分代码,中间的那段插入语句是否有问题,还有,能不能请高手们留个邮箱,我把全部代码发给你们,帮我测试一下
if(s.equals("出售")){
try{
SimpleDateFormat d=new SimpleDateFormat("yyyyMMddhhmmss");
String no=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("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jbdc:odbc:MyOdbc","","");
Statement stmt=con.createStatement();
stmt.executeUpdate("insert into [Sheet1$] values('"+no+"','"+store+"','"+pro+"',"+price+","+quantity+","+total+");");
lb6.setText("成功出售");
con.close();
}
catch(Exception e){
System.out.println("connect fail");
}
}
else if(s.equals("所有销售记录")){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jbdc:odbc:MyOdbc","","");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from [Sheet1$];");
while(rs.next()){
String st1,st2;
st1=new String(rs.getString(2).getBytes("ISO8859_1"));
st2=new String(rs.getString(3).getBytes("ISO8859_1"));
System.out.print("编号:"+rs.getString(1)+" ");
System.out.print("连锁店:"+st1+" ");
System.out.print("商品:"+st2+" ");
System.out.print("单价:"+rs.getString(4)+" ");
System.out.print("数量:"+rs.getString(5)+" ");
System.out.println("总价:"+rs.getString(6));
}
con.close();
}
catch(Exception e){
System.out.print("查询失败");
}
}//部分代码,中间的那段插入语句是否有问题,还有,能不能请高手们留个邮箱,我把全部代码发给你们,帮我测试一下
stmt.executeUpdate("insert into ("no,store,pro,price,quantity,total") values('"+no+"','"+store+"','"+pro+"',"+price+","+quantity+","+total+");");
这样行不你看看
吧最后的; 分号去掉
把异常信息显示出来才能发现问题呀!
吧最后的; 分号去掉