向一个本地数据库写东西时,若用run就无法写入,但用debug(单步操作)就能写入???
而且run时若写入一个主键重复的数据,会报错(即无法写入重复主键的数据),用不重复的时,不报错,但没写进去。
那位能解释一下吗?
先谢了

解决方案 »

  1.   

    说详细一点啊?
    这个报错是:java里报错,还是你单独在Acess里运行sql出错
      

  2.   

    java中报错,代码如下:
    public class AccessTest {
    static Connection con;

        //static Statement sm_account;
        //static ResultSet rs_account;
        static PreparedStatement ps_account;
    public static void main(String[] args) {
    try
            {
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            }
            catch (ClassNotFoundException ex) 
            {
                /** @todo Handle this exception */
            }
            try
    {
             con=(Connection) DriverManager.getConnection("jdbc:odbc:AccountDB");
    }
            catch(SQLException ex)
            {
                System.out.println(ex);
            } 
            try
    {
            
             ps_account=con.prepareStatement("insert into AccountTable values(?,?,?,?,?)");
    }
            catch(SQLException ex)
    {
             System.out.println(ex);
    }
            add(2,"q","q","q","q");
    }
    public static void add(int id,String name,String pass,String email,String friendlist)
    {
    try
    {
    ps_account.setInt(1,id);
    ps_account.setString(2,name);
    ps_account.setString(3,pass);
    ps_account.setString(4,email);
    ps_account.setString(5,friendlist);
    ps_account.executeUpdate();
    }
    catch(SQLException ex)
    {
             System.out.println(ex);
    }
    }