私の主なキーはempid
とdate
です。私がしたいのは、従業員がSQL Serverに値を挿入し、同じ日に値をデータベースに挿入しようとした場合、主キーが競合するはずです。私は、彼/彼女は私はあなたのデータベーステーブルのdat
日付列に一意制約を追加することによって、これについて行くだろうというどのようにsqlserverから私のJavaプログラマーにエラーメッセージを取得できます
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String g = jComboBox1.getSelectedItem().toString();
if(g.equals("--Select Your Employee ID--"))
{
jLabel6.setForeground(Color.RED);
jLabel6.setText("Please Select Your ID ");
}
else{
jLabel6.setText("");
}
String a =jTextArea1.getText();
if(a.equals("")){
jLabel7.setForeground(Color.RED);
jLabel7.setText("Please Fill the Report ");
}
else{
jLabel7.setText("");
}
try{
String url="jdbc:sqlserver://localhost:1433;databaseName=gym2 ";
String username = "mali";
String password = "12345";
Connection con =DriverManager.getConnection(url,username,password);
Statement st = con.createStatement();
ResultSet rs;
Calendar cal = Calendar.getInstance();
SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
String sql = "INSERT INTO report(empid,dat,rep) VALUES('"+g+"','"+format1.format(cal.getTime())+"','"+a+"')" ;
rs= st.executeQuery(sql);
jComboBox1.addItem("--Select Your Employee ID--");
}
catch(Exception e){
}
私はそれをlableに得ることができますか?役に立たなかった –
あなたのコメントが分かりません。 –
jframeでjlableに結果を得ることができません –