アプリケーションのデータベースを作成するための 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 という名前のデータベースは作成されません。私のプログラムに何が起こったのか。誰でも私を助けてください