このエラーを回避しようとしています。ここに手を差し伸べてもよろしいですか? 以下は私のコードです。上記のコードをエラー:カラム数が値のカウントと一致しません。
package Viewer;
import Model.JDBC;
import java.sql.ResultSet;
import javax.swing.JOptionPane;
public class User extends javax.swing.JFrame
{
Model.JDBC j=new JDBC();
public User()
{
initComponents();
eid.grabFocus();
}
@SuppressWarnings("unchecked")
private void saveActionPerformed(java.awt.event.ActionEvent evt)
{
try
{
ResultSet rs = j.getData("select eid from user where eid='" + eid.getText() + "'");
if (rs.next())
{
if (eid.getText().equals(rs.getString(1)))
{
JOptionPane.showMessageDialog(null, "Existing User Name");
pwd.setText("");
cpwd.setText("");
}
}
else
{
if (eid.getText().isEmpty())
{
JOptionPane.showMessageDialog(null,"Enter User Name");
eid.grabFocus();
}
else if (pwd.getText().isEmpty())
{
JOptionPane.showMessageDialog(null,"Enter Password");
}
else if (pwd.getText().isEmpty())
{
JOptionPane.showMessageDialog(null,"Enter Password");
}
else
{
String pass = new String(pwd.getPassword());
String pas1 = new String(cpwd.getPassword());
if (pass.equals(pas1))
{
String ps = new String(pwd.getPassword());
String s = ps;
try
{
j.putData("insert into user values ('" + eid.getText() + "','" + s + "','" + ulevel.getSelectedItem() + "','"+pwd.getText()+"','"+cpwd.getText()+"')");
JOptionPane.showMessageDialog(null,"User Added Successfully.. ");
j.getCon().close();
clear();
}
catch (Exception e)
{
System.out.println(e + "101 User Adding");
}
}
else
{
JOptionPane.showMessageDialog(null,"Password Not Match");
pwd.grabFocus();
pwd.setText("");
cpwd.setText("");
}
}
}
}
catch (Exception e)
{
System.out.println(e);
}
}
private void deleteActionPerformed(java.awt.event.ActionEvent evt)
{
try
{
ResultSet rs = j.getData("select * from user where eid='" + eid.getText() + "'");
if (rs.next())
{
if (rs.getString(1).equals(eid.getText()))
{
String a = (pwd.getText());
String b = (cpwd.getText());
if((rs.getString(2).equals(a)) && (rs.getString(2).equals(b)))
{
int t = JOptionPane.showConfirmDialog(null, "Are You Sure...?");
if(t==JOptionPane.YES_OPTION)
{
j.putData("delete from user where eid='"+eid.getText()+"'");
clear();
}
}
else if(!rs.getString(2).equals(a))
{
JOptionPane.showMessageDialog(null, "Password Not Match");
pwd.setText("");
cpwd.setText("");
}
else if(!rs.getString(2).equals(b))
{
JOptionPane.showMessageDialog(null, "Password Not Match");
pwd.setText("");
cpwd.setText("");
}
}
}
else
{
JOptionPane.showMessageDialog(null, "Invalid User Name");
clear();
}
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
private void eidKeyPressed(java.awt.event.KeyEvent evt)
{
if (evt.getKeyCode() == 10)
{
if (eid.getText().isEmpty())
{
//ms.massage("Enter User Name");
eid.grabFocus();
}
ulevel.grabFocus();
}
}
private void ulevelKeyPressed(java.awt.event.KeyEvent evt)
{
if (evt.getKeyCode() == 10)
{
pwd.grabFocus();
}
}
private void pwdKeyPressed(java.awt.event.KeyEvent evt)
{
if (evt.getKeyCode() == 10)
{
if (pwd.getText().isEmpty())
{
JOptionPane.showMessageDialog(null,"Enter Password");
}
else
{
cpwd.grabFocus();
}
}
}
private void cpwdKeyPressed(java.awt.event.KeyEvent evt)
{
if (evt.getKeyCode() == 10)
{
String pass = new String(pwd.getPassword());
System.out.println(pass);
String pas1 = new String(cpwd.getPassword());
System.out.println(pas1);
if (pass.equals(pas1))
{
save.grabFocus();
}
else
{
JOptionPane.showMessageDialog(null,"Password Not Match");
pwd.grabFocus();
pwd.setText("");
cpwd.setText("");
}
}
}
private void pwdActionPerformed(java.awt.event.ActionEvent evt)
{}
public void clear()
{
eid.setText("");
ulevel.setSelectedItem("Admin");
pwd.setText("");
cpwd.setText("");
}
public static void main(String args[])
{
try
{
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels())
{
if ("Nimbus".equals(info.getName()))
{
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
}
catch (ClassNotFoundException ex)
{
java.util.logging.Logger.getLogger(User.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
catch (InstantiationException ex)
{
java.util.logging.Logger.getLogger(User.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
catch (IllegalAccessException ex)
{
java.util.logging.Logger.getLogger(User.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
catch (javax.swing.UnsupportedLookAndFeelException ex)
{
java.util.logging.Logger.getLogger(User.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
java.awt.EventQueue.invokeLater(new Runnable()
{
public void run()
{
new User().setVisible(true);
}
});
}
private javax.swing.JPasswordField cpwd;
private javax.swing.JButton delete;
private javax.swing.JTextField eid;
private javax.swing.JFrame jFrame1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JPanel jPanel1;
private javax.swing.JPasswordField pwd;
private javax.swing.JButton save;
private javax.swing.JButton search;
private javax.swing.JComboBox<String> ulevel;
private javax.swing.JButton update;
}
、私は「userregistry」という名前のユーザー情報の取得、フォームを実行するために、「EID」という名前のテキストフィールドには、ユーザー名を取得しますスイングアプリケーション、コンボボックス名「ulevel」をしようとしていましたユーザのタイプ(管理者/ユーザ)と、パスワードを与えるための "pwd"というパスワードフィールドと、パスワードを確認するための "cpwd"という別のパスワードフィールドを与えます。保存、検索、更新、削除の4つのボタンがあり、上記の操作を実行します(検索と更新のコードはここにはありません)。
は私が
mysql> create table user(eid varchar(45) primary key, ulevel int, pwd varchar(45
), cpwd varchar(45));
私の問題はthis-である。この構文で作成されたSQLテーブルを持っている:私は詳細を入力し、ボタンのNetBeansを保存]をクリックすると
java.sql.SQLException: Column count doesn't match value count at row 101 User Adding
は何ができるかと言いますこれの理由?
私はあなたのクエリで使用列の数が多いため、このエラーを取得し、それは私にメッセージ
java.sql.SQLException: Column count doesn't match value count at row 101 User Adding
どのような方法でこのエラーが発生しますか? –