0

アプリケーションのデータベースを作成するための Java ページに小さなプログラムがあります。コードは次のとおりです。データベースは mysql にありますが、うまくいきません。私のコードは正しいと思います。

private DataBaseSource dbSource = new DataBaseSourceImpl();
private Connection connection = null;
private Statement statement = null;
private PreparedStatement preparedStatement = null;
private ResultSet resultSet = null;


/** Creates new form LoginScreen */
public LoginScreen() {
    initComponents();
    Container c =this.getContentPane();
    c.setBackground(Color.WHITE);

    connection = (Connection) dbSource.getConnection();

    signInBtn.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            String uname = usrNameTxt.getText();
            char[] pword = pwordTxt.getPassword();
            String password = new String(pword);

            if(uname.equals("")&& password.equals("")){


            Util.showErrorMessageDialog("Please fill all the fields.");


            }else{

                if(uname.equals("") || uname.equals(" ")&& ! password.equals("")){


                 Util.showErrorMessageDialog("Login ID left blank");

            }else{

                if (password.equals("") || password.equals(" ")&& uname.equals("")) {

                Util.showErrorMessageDialog("Password left blank.");

                }else{

                authenticateLogin();

                }

            }


            }
        }
    });
}
public void authenticateLogin() {
    try {
        preparedStatement = (PreparedStatement) connection.prepareStatement("CREATE DATABASE IF NOT EXIST macfast");
        preparedStatement.executeQuery();

    } catch (SQLException ex) {
        Logger.getLogger(LoginScreen.class.getName()).log(Level.SEVERE, null, ex);
    }


}

public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
            new LoginScreen().setVisible(true);

        }
    });
}

// Variables declaration - do not modify                     
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JPanel jPanel2;
private javax.swing.JPasswordField pwordTxt;
private javax.swing.JButton signInBtn;
private javax.swing.JTextField usrNameTxt;
// End of variables declaration                   

}

これは私のコード例ですが、上記の例に示されている macfast という名前のデータベースは作成されません。私のプログラムに何が起こったのか。誰でも私を助けてください

4

2 に答える 2

0

DataBaseSourceImpl() のコードを提供します。同じ値を取得しようとしているときに、どの値を渡そうとしていますか。代わりに DataSource を使用してみませんか。アプリケーションが DB に接続できるかどうかをテストするには、より単純なプログラムを作成してみる必要があります。

現時点でどのようなエラーが発生していますか。

于 2013-07-22T07:43:11.057 に答える