need JAVA JDBC logic to connect to database (data given by users in GUI)and run select sql file on selected db by user -
i have designed gui user select type of database want connect , browse sql file want run on selected db. below program.
i need jdbc logic connect selected database , run sql file having multiple queries create table view etc , give log file user.
/* * change license header, choose license headers in project properties. * change template file, choose tools | templates * , open template in editor. */ package my.dbconnect; import java.io.file; import javax.swing.jfilechooser; /** * * @author shmatada */ public class dbconnect extends javax.swing.jframe { /** * creates new form dbconnect */ public dbconnect() { initcomponents(); } /** * method called within constructor initialize form. * warning: not modify code. content of method * regenerated form editor. */ @suppresswarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="generated code"> private void initcomponents() { jpanel1 = new javax.swing.jpanel(); jcombobox1 = new javax.swing.jcombobox(); jlabel1 = new javax.swing.jlabel(); jpanel2 = new javax.swing.jpanel(); jlabel2 = new javax.swing.jlabel(); jlabel3 = new javax.swing.jlabel(); jlabel4 = new javax.swing.jlabel(); jlabel5 = new javax.swing.jlabel(); jlabel6 = new javax.swing.jlabel(); jtextfield2 = new javax.swing.jtextfield(); jtextfield3 = new javax.swing.jtextfield(); jtextfield4 = new javax.swing.jtextfield(); jtextfield5 = new javax.swing.jtextfield(); jpasswordfield1 = new javax.swing.jpasswordfield(); jtextfield6 = new javax.swing.jtextfield(); jbutton3 = new javax.swing.jbutton(); jlabel7 = new javax.swing.jlabel(); jbutton1 = new javax.swing.jbutton(); jbutton2 = new javax.swing.jbutton(); setdefaultcloseoperation(javax.swing.windowconstants.exit_on_close); jpanel1.setborder(javax.swing.borderfactory.createtitledborder(null, "db details", javax.swing.border.titledborder.default_justification, javax.swing.border.titledborder.default_position, new java.awt.font("times new roman", 1, 12))); // noi18n jpanel1.setname(""); // noi18n jcombobox1.setmodel(new javax.swing.defaultcomboboxmodel(new string[] { "oracle", "db2", "mysql" })); jcombobox1.settooltiptext("select type of db"); jcombobox1.setautoscrolls(true); jcombobox1.addactionlistener(new java.awt.event.actionlistener() { public void actionperformed(java.awt.event.actionevent evt) { jcombobox1actionperformed(evt); } }); jlabel1.settext("db type:"); jpanel2.setborder(javax.swing.borderfactory.createtitledborder(null, "", javax.swing.border.titledborder.default_justification, javax.swing.border.titledborder.default_position, new java.awt.font("tahoma", 1, 12))); // noi18n jlabel2.settext("db name:"); jlabel3.settext("db host:"); jlabel4.settext("db port:"); jlabel5.settext("username:"); jlabel6.settext("password"); jtextfield3.setfont(new java.awt.font("times new roman", 0, 11)); // noi18n jtextfield3.settooltiptext("mention db name want connect to"); jtextfield6.addactionlistener(new java.awt.event.actionlistener() { public void actionperformed(java.awt.event.actionevent evt) { jtextfield6actionperformed(evt); } }); jbutton3.settext("browse"); jbutton3.addactionlistener(new java.awt.event.actionlistener() { public void actionperformed(java.awt.event.actionevent evt) { jbutton3actionperformed(evt); } }); jlabel7.settext("sql file"); javax.swing.grouplayout jpanel2layout = new javax.swing.grouplayout(jpanel2); jpanel2.setlayout(jpanel2layout); jpanel2layout.sethorizontalgroup( jpanel2layout.createparallelgroup(javax.swing.grouplayout.alignment.leading) .addgroup(javax.swing.grouplayout.alignment.trailing, jpanel2layout.createsequentialgroup() .addcontainergap() .addgroup(jpanel2layout.createparallelgroup(javax.swing.grouplayout.alignment.leading) .addcomponent(jlabel2) .addcomponent(jlabel3) .addcomponent(jlabel6) .addcomponent(jlabel4) .addcomponent(jlabel5) .addcomponent(jlabel7)) .addpreferredgap(javax.swing.layoutstyle.componentplacement.unrelated) .addgroup(jpanel2layout.createparallelgroup(javax.swing.grouplayout.alignment.leading) .addcomponent(jtextfield2) .addcomponent(jtextfield3) .addcomponent(jtextfield4) .addcomponent(jtextfield5) .addcomponent(jpasswordfield1) .addcomponent(jtextfield6)) .addgap(6, 6, 6) .addcomponent(jbutton3) .addcontainergap()) ); jpanel2layout.linksize(javax.swing.swingconstants.horizontal, new java.awt.component[] {jlabel2, jlabel3, jlabel4, jlabel5, jlabel6}); jpanel2layout.setverticalgroup( jpanel2layout.createparallelgroup(javax.swing.grouplayout.alignment.leading) .addgroup(jpanel2layout.createsequentialgroup() .addcontainergap() .addgroup(jpanel2layout.createparallelgroup(javax.swing.grouplayout.alignment.baseline) .addcomponent(jlabel2, javax.swing.grouplayout.default_size, javax.swing.grouplayout.default_size, short.max_value) .addcomponent(jtextfield2)) .addpreferredgap(javax.swing.layoutstyle.componentplacement.related) .addgroup(jpanel2layout.createparallelgroup(javax.swing.grouplayout.alignment.baseline) .addcomponent(jlabel3, javax.swing.grouplayout.default_size, javax.swing.grouplayout.default_size, short.max_value) .addcomponent(jtextfield3)) .addpreferredgap(javax.swing.layoutstyle.componentplacement.related) .addgroup(jpanel2layout.createparallelgroup(javax.swing.grouplayout.alignment.baseline) .addcomponent(jlabel4, javax.swing.grouplayout.default_size, javax.swing.grouplayout.default_size, short.max_value) .addcomponent(jtextfield4)) .addpreferredgap(javax.swing.layoutstyle.componentplacement.related) .addgroup(jpanel2layout.createparallelgroup(javax.swing.grouplayout.alignment.baseline) .addcomponent(jlabel5, javax.swing.grouplayout.default_size, javax.swing.grouplayout.default_size, short.max_value) .addcomponent(jtextfield5)) .addpreferredgap(javax.swing.layoutstyle.componentplacement.related) .addgroup(jpanel2layout.createparallelgroup(javax.swing.grouplayout.alignment.leading) .addgroup(jpanel2layout.createsequentialgroup() .addcomponent(jpasswordfield1) .addgap(12, 12, 12) .addgroup(jpanel2layout.createparallelgroup(javax.swing.grouplayout.alignment.leading) .addgroup(jpanel2layout.createsequentialgroup() .addgap(3, 3, 3) .addcomponent(jtextfield6)) .addgroup(jpanel2layout.createparallelgroup(javax.swing.grouplayout.alignment.baseline) .addcomponent(jbutton3) .addcomponent(jlabel7)))) .addgroup(javax.swing.grouplayout.alignment.trailing, jpanel2layout.createsequentialgroup() .addcomponent(jlabel6, javax.swing.grouplayout.default_size, javax.swing.grouplayout.default_size, short.max_value) .addgap(37, 37, 37)))) ); javax.swing.grouplayout jpanel1layout = new javax.swing.grouplayout(jpanel1); jpanel1.setlayout(jpanel1layout); jpanel1layout.sethorizontalgroup( jpanel1layout.createparallelgroup(javax.swing.grouplayout.alignment.leading) .addgroup(jpanel1layout.createsequentialgroup() .addcontainergap() .addgroup(jpanel1layout.createparallelgroup(javax.swing.grouplayout.alignment.leading) .addgroup(javax.swing.grouplayout.alignment.trailing, jpanel1layout.createsequentialgroup() .addgap(0, 0, short.max_value) .addcomponent(jlabel1) .addpreferredgap(javax.swing.layoutstyle.componentplacement.unrelated) .addcomponent(jcombobox1, javax.swing.grouplayout.preferred_size, 306, javax.swing.grouplayout.preferred_size)) .addcomponent(jpanel2, javax.swing.grouplayout.default_size, javax.swing.grouplayout.default_size, short.max_value)) .addcontainergap()) ); jpanel1layout.setverticalgroup( jpanel1layout.createparallelgroup(javax.swing.grouplayout.alignment.leading) .addgroup(jpanel1layout.createsequentialgroup() .addcontainergap() .addgroup(jpanel1layout.createparallelgroup(javax.swing.grouplayout.alignment.baseline) .addcomponent(jcombobox1, javax.swing.grouplayout.preferred_size, javax.swing.grouplayout.default_size, javax.swing.grouplayout.preferred_size) .addcomponent(jlabel1)) .addgap(18, 18, 18) .addcomponent(jpanel2, javax.swing.grouplayout.preferred_size, javax.swing.grouplayout.default_size, javax.swing.grouplayout.preferred_size) .addcontainergap(32, short.max_value)) ); jbutton1.settext("run"); jbutton1.settooltiptext("select ok run sql on db"); jbutton1.setverifyinputwhenfocustarget(false); jbutton1.addactionlistener(new java.awt.event.actionlistener() { public void actionperformed(java.awt.event.actionevent evt) { jbutton1actionperformed(evt); } }); jbutton2.settext("cancel"); jbutton2.addactionlistener(new java.awt.event.actionlistener() { public void actionperformed(java.awt.event.actionevent evt) { jbutton2actionperformed(evt); } }); javax.swing.grouplayout layout = new javax.swing.grouplayout(getcontentpane()); getcontentpane().setlayout(layout); layout.sethorizontalgroup( layout.createparallelgroup(javax.swing.grouplayout.alignment.leading) .addgroup(layout.createsequentialgroup() .addcontainergap() .addcomponent(jpanel1, javax.swing.grouplayout.default_size, javax.swing.grouplayout.default_size, short.max_value) .addcontainergap()) .addgroup(javax.swing.grouplayout.alignment.trailing, layout.createsequentialgroup() .addcontainergap(javax.swing.grouplayout.default_size, short.max_value) .addcomponent(jbutton1) .addpreferredgap(javax.swing.layoutstyle.componentplacement.related) .addcomponent(jbutton2) .addgap(32, 32, 32)) ); layout.linksize(javax.swing.swingconstants.horizontal, new java.awt.component[] {jbutton1, jbutton2}); layout.setverticalgroup( layout.createparallelgroup(javax.swing.grouplayout.alignment.leading) .addgroup(layout.createsequentialgroup() .addcontainergap() .addcomponent(jpanel1, javax.swing.grouplayout.preferred_size, javax.swing.grouplayout.default_size, javax.swing.grouplayout.preferred_size) .addpreferredgap(javax.swing.layoutstyle.componentplacement.related) .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.baseline) .addcomponent(jbutton1) .addcomponent(jbutton2)) .addcontainergap(javax.swing.grouplayout.default_size, short.max_value)) ); pack(); }// </editor-fold> private void jcombobox1actionperformed(java.awt.event.actionevent evt) { // todo add handling code here: } private void jbutton1actionperformed(java.awt.event.actionevent evt) { // todo add handling code here: } private void jbutton2actionperformed(java.awt.event.actionevent evt) { system.exit(0); } private void jtextfield6actionperformed(java.awt.event.actionevent evt) { // todo add handling code here: } private void jbutton3actionperformed(java.awt.event.actionevent evt) { jfilechooser chooser = new jfilechooser(); chooser.showopendialog(null); file f =chooser.getselectedfile(); string filename=f.getabsolutepath(); jtextfield6.settext(filename); } /** * @param args command line arguments */ public static void main(string args[]) { /* set nimbus , feel */ //<editor-fold defaultstate="collapsed" desc=" , feel setting code (optional) "> /* if nimbus (introduced in java se 6) not available, stay default , feel. * details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { (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(dbconnect.class.getname()).log(java.util.logging.level.severe, null, ex); } catch (instantiationexception ex) { java.util.logging.logger.getlogger(dbconnect.class.getname()).log(java.util.logging.level.severe, null, ex); } catch (illegalaccessexception ex) { java.util.logging.logger.getlogger(dbconnect.class.getname()).log(java.util.logging.level.severe, null, ex); } catch (javax.swing.unsupportedlookandfeelexception ex) { java.util.logging.logger.getlogger(dbconnect.class.getname()).log(java.util.logging.level.severe, null, ex); } //</editor-fold> /* create , display form */ java.awt.eventqueue.invokelater(new runnable() { public void run() { new dbconnect().setvisible(true); } }); } // variables declaration - not modify private javax.swing.jbutton jbutton1; private javax.swing.jbutton jbutton2; private javax.swing.jbutton jbutton3; private javax.swing.jcombobox jcombobox1; 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.jlabel jlabel7; private javax.swing.jpanel jpanel1; private javax.swing.jpanel jpanel2; private javax.swing.jpasswordfield jpasswordfield1; private javax.swing.jtextfield jtextfield2; private javax.swing.jtextfield jtextfield3; private javax.swing.jtextfield jtextfield4; private javax.swing.jtextfield jtextfield5; private javax.swing.jtextfield jtextfield6; // end of variables declaration }
Comments
Post a Comment