代码如下:
import java.sql.*; 
 public class au
  { 
   public static void main(String args[])throws Exception
    { 
     String url = "jdbc:odbc:dxq"; //取得连接的url名,注意dxq是dsn名 
     Connection con; //实例化一个Connection对象 
     Statement stmt; 
     String query = "select * from workerpay"; //选择表中的数据输出
      try 
      { 
       Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//加载jdbc-odbc桥驱动
      } 
      catch(java.lang.ClassNotFoundException e) 
       { System.err.print("ClassNotFoundException: "); //加载jdbc-odbc桥错误 
       System.err.println(e.getMessage());  //其他错误
       } 
      try 
      {
       con = DriverManager.getConnection(url, "sa", "");//数据库连接
       stmt = con.createStatement();//Create 一个声明 
       String s1,s2,s3;
       s1="cc";
       s2="p3";
       s3="060303";
       int k;
       k=BasicIo.readInteger();//输入k的值
       PreparedStatement pstmt=null;
       String sql; 
       sql="insert into workerpay  values(?,?,?,?)";
       pstmt = conn.prepareStatement(sql);//此处提示出错
       pstmt.setString(1,s1); 
                           pstmt.setString(2,s2); 
                           pstmt.setInt(3,k); 
                           pstmt.setString(4,s3);
                            pstmt.executeUpdate();        
ResultSet rs = stmt.executeQuery(query); 
System.out.println("workerpay表中的数据如下(原始数据)"); 
//下面的语句使用了一个while循环打印出了col_link表中的所有的数据
 System.out.println("员工姓名 "+"       "+"零件名称"+"       "+"零件数量"+"       "+"日期");
 System.out.println("---------------"+" "+"----------------"); 
  while (rs.next()) 
  { String w = rs.getString("workername"); 
   String p = rs.getString("product"); 
   int n = rs.getInt("productnum");
   String d = rs.getString("indate");
     stmt.close(); 
     con.close();      
     } 
     catch(SQLException ex) 
     { System.err.println("SQLException: " + ex.getMessage());      
     }
   }
  }
编译时
pstmt = conn.prepareStatement(sql);//此处提示出错
Au.java:33: cannot resolve symbol
symbol  : variable conn
location: class au
                        pstmt = conn.prepareStatement(sql);
                                ^
1 error
我是想把自己输入的数据插入到数据库中,不知道有什么办法能解决?望高人指点谢谢!