I have a small progam in java page to create database for my application.Here is the code.Database is at mysql.But is does not work for me.I think my code is correct.
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
}
This is my code example.But it does not create database named as macfast... shown in the above example. What happened for my program. Any one please help me