阅读背景:

为什么我无法从netbeans界面“更新”数据到数据库。

来源:互联网 

<html>
<body>
<pre>





geting a error when click on the update button as : "com.microsoft.sqlserver.jdbc.SQLServerException: Violation of PRIMARY KEY constraint 'PK_customer'. Cannot insert duplication key in object 'dbo.Customer'. The duplication key value is ()."   



private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        
       try{
        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
        String url="jdbc:sqlserver://localhost:1433;databaseName=77OOP062;user=sa;password=hnd";
        Connection conn= DriverManager.getConnection(url);


String value1=jTextFieldCustomerName.getText();
String value2=jTextFieldHomeAddress.getText();
String value3=jTextFieldNIC.getText();
String value4=jTextFieldEmailAddress.getText();
String value5=jTextFieldContactNo.getText();
String value6=jLabel7.getText();


pst=conn.prepareStatement("update Customer set CustomerName=?,HomeAddress=?,NIC=?,EmailAddress=?,ContactNo=?,InvoiceNo=?"); 
pst.setString(1,value1);
pst.setString(2,value2);
pst.setString(3,value3);
pst.setString(4,value4);
pst.setString(5,value5);
pst.setString(6,value6);
pst.executeUpdate();
              
              JOptionPane.showMessageDialog(null, "Güncellendi");



}catch(Exception e){;

        JOptionPane.showMessageDialog(null, e);


}
  distable();
       
    }   






</pre>
</body>
</html><html>
<body>
<pre>





geting a e



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: