java - Create Database -
i have small progam in java page create database application.here code.database @ mysql.but not work me.i think code 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 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 - 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 code example.but not create database named macfast... shown in above example. happened program. 1 please me
you need use executeupdate
instead of executequery
.
statement st = connection.createstatement(); st.executeupdate("create database if not exists macfast"); st.close();
Comments
Post a Comment