swing - INSERT stsement not working in java program -
hi have program connects embedded derby database , should reference database data. trying test database out using simple insert statement, not working. please help.
import java.awt.borderlayout; import java.awt.eventqueue; import java.awt.label; import javax.swing.jframe; import javax.swing.jpanel; import javax.swing.border.emptyborder; import javax.swing.jtabbedpane; import javax.swing.jlabel; import javax.swing.jtextfield; import javax.swing.buttongroup; import javax.swing.jcombobox; import javax.swing.jradiobutton; import java.awt.button; import java.awt.event.actionlistener; import java.awt.event.actionevent; import javax.swing.jbutton; import javax.swing.jlist; import java.awt.list; import java.sql.connection; import java.sql.drivermanager; import java.sql.resultset; import java.sql.sqlexception; import java.sql.statement; import java.sql.resultsetmetadata; public class auto extends javax.swing.jframe implements actionlistener { /** * */ private static final long serialversionuid = -5777093322764526515l; private jpanel contentpane; private jtextfield f_name; private jtextfield l_name; private jtextfield f_name2; private jtextfield l_name2; private jtextfield age; private jtextfield issuing; private jtextfield liscense_num; private jtextfield rental; private jtextfield return_d; private jtextfield total; private jtextfield age2; private jtextfield issuing2; private jtextfield liscense_num2; private jtextfield rental2; private jtextfield return_d2; private jtextfield total2; private jtextfield agreement_id; private button submit_button; private button clear_button; private jbutton load_button; private button update_button; private button return_car; private jcombobox<?> car_select, car_select2; private jradiobutton cc_button; private jradiobutton cc_button2; private jradiobutton debit_button; private jradiobutton debit_button2; private static string url; private string com; private static connection myconnection; private static statement mystatement; /** * launch application. */ public static void main(string[] args) throws sqlexception, classnotfoundexception { eventqueue.invokelater(new runnable() { public void run() { try { class.forname("org.apache.derby.jdbc.embeddeddriver"); url = "jdbc:derby:mydb;create=true"; myconnection = drivermanager.getconnection(url); mystatement = myconnection.createstatement( ); auto frame = new auto(); frame.setvisible(true); } catch (exception e) { e.printstacktrace(); } } }); } /** * create frame. */ public auto() { setdefaultcloseoperation(jframe.exit_on_close); setbounds(100, 100, 694, 497); contentpane = new jpanel(); contentpane.setborder(new emptyborder(5, 5, 5, 5)); setcontentpane(contentpane); contentpane.setlayout(null); jtabbedpane auto_pane = new jtabbedpane(jtabbedpane.top); auto_pane.setbounds(5, 5, 422, 432); contentpane.add(auto_pane); jpanel new_rent = new jpanel(); auto_pane.addtab("new rental", null, new_rent, null); new_rent.setlayout(null); jlabel first_name = new jlabel("first name: "); first_name.setbounds(12, 8, 84, 16); new_rent.add(first_name); f_name = new jtextfield(15); f_name.setbounds(97, 5, 116, 22); new_rent.add(f_name); f_name.setcolumns(10); l_name = new jtextfield(15); l_name.setbounds(97, 40, 116, 22); l_name.setcolumns(10); new_rent.add(l_name); jlabel last_name = new jlabel("last name: "); last_name.setbounds(12, 43, 84, 16); new_rent.add(last_name); jlabel age = new jlabel("age: "); age.setbounds(12, 76, 84, 16); new_rent.add(age); age = new jtextfield(2); age.setbounds(97, 75, 35, 22); age.setcolumns(10); new_rent.add(age); jlabel liscense = new jlabel("license #: "); liscense.setbounds(12, 113, 84, 16); new_rent.add(liscense); jlabel issuing_st = new jlabel("issuing state: "); issuing_st.setbounds(12, 146, 84, 16); new_rent.add(issuing_st); issuing = new jtextfield(2); issuing.setbounds(97, 143, 116, 22); issuing.setcolumns(10); new_rent.add(issuing); liscense_num = new jtextfield(13); liscense_num.setbounds(97, 110, 116, 22); liscense_num.setcolumns(10); new_rent.add(liscense_num); string[] carstrings = { "compact", "midsized", "standard", "full size", "suv", "mini van" }; car_select = new jcombobox<object>(carstrings); car_select.setbounds(97, 178, 112, 22); new_rent.add(car_select); jlabel car_type = new jlabel("car type:"); car_type.setbounds(12, 181, 84, 16); new_rent.add(car_type); jlabel rent_date = new jlabel("rental date:"); rent_date.setbounds(12, 216, 84, 16); new_rent.add(rent_date); rental = new jtextfield(10); rental.setbounds(97, 213, 116, 22); rental.setcolumns(10); new_rent.add(rental); jlabel return_date = new jlabel("return date:"); return_date.setbounds(12, 251, 84, 16); new_rent.add(return_date); return_d = new jtextfield(10); return_d.setbounds(97, 248, 116, 22); return_d.setcolumns(10); new_rent.add(return_d); jlabel total_num = new jlabel("total:"); total_num.setbounds(12, 283, 84, 16); new_rent.add(total_num); total = new jtextfield(7); total.setbounds(97, 280, 116, 22); total.setcolumns(10); new_rent.add(total); jlabel payment_type = new jlabel("payment type:"); payment_type.setbounds(12, 317, 100, 16); new_rent.add(payment_type); cc_button = new jradiobutton("credit card"); cc_button.setbounds(128, 313, 127, 25); new_rent.add(cc_button); debit_button = new jradiobutton("debit"); debit_button.setbounds(259, 313, 127, 25); new_rent.add(debit_button); buttongroup group = new buttongroup(); group.add(debit_button); group.add(cc_button); submit_button = new button("submit"); submit_button.setbounds(12, 356, 99, 24); submit_button.addactionlistener(this); new_rent.add(submit_button); clear_button = new button("clear form"); clear_button.setbounds(128, 356, 99, 24); clear_button.addactionlistener(this); new_rent.add(clear_button); jpanel current_rent = new jpanel(); auto_pane.addtab("current rental", null, current_rent, null); current_rent.setlayout(null); load_button = new jbutton("load current rental agreements"); load_button.addactionlistener(this); load_button.setbounds(12, 13, 393, 25); current_rent.add(load_button); list load_list = new list(); load_list.setbounds(12, 54, 393, 229); current_rent.add(load_list); jpanel rental_ret = new jpanel(); auto_pane.addtab("rental details", null, rental_ret, null); rental_ret.setlayout(null); jlabel first_name2 = new jlabel("first name: "); first_name2.setbounds(15, 48, 71, 16); rental_ret.add(first_name2); f_name2 = new jtextfield(15); f_name2.setbounds(109, 45, 116, 22); rental_ret.add(f_name2); f_name2.setcolumns(10); l_name2 = new jtextfield(15); l_name2.setbounds(109, 74, 116, 22); l_name2.setcolumns(10); rental_ret.add(l_name2); jlabel last_name2 = new jlabel("last name: "); last_name2.setbounds(15, 77, 69, 16); rental_ret.add(last_name2); age2 = new jtextfield(2); age2.setbounds(109, 109, 116, 22); age2.setcolumns(10); rental_ret.add(age2); jlabel liscense2 = new jlabel("license #: "); liscense2.setbounds(15, 141, 64, 16); rental_ret.add(liscense2); jlabel issuing_st2 = new jlabel("issuing state: "); issuing_st2.setbounds(15, 170, 83, 16); rental_ret.add(issuing_st2); issuing2 = new jtextfield(2); issuing2.setbounds(109, 167, 116, 22); issuing2.setcolumns(10); rental_ret.add(issuing2); liscense_num2 = new jtextfield(13); liscense_num2.setbounds(109, 138, 116, 22); liscense_num2.setcolumns(10); rental_ret.add(liscense_num2); car_select2 = new jcombobox<object>(carstrings); car_select2.setbounds(109, 197, 116, 22); rental_ret.add(car_select2); jlabel car_type2 = new jlabel("car type:"); car_type2.setbounds(15, 199, 57, 16); rental_ret.add(car_type2); jlabel rent_date2 = new jlabel("rental date:"); rent_date2.setbounds(15, 234, 71, 16); rental_ret.add(rent_date2); jtextfield rental2 = new jtextfield(10); rental2.setbounds(109, 231, 116, 22); rental2.setcolumns(10); rental_ret.add(rental2); jlabel return_date2 = new jlabel("return date:"); return_date2.setbounds(15, 269, 73, 16); rental_ret.add(return_date2); jtextfield return_d2 = new jtextfield(10); return_d2.setcolumns(10); return_d2.setbounds(109, 266, 116, 22); rental_ret.add(return_d2); jlabel total_num2 = new jlabel("total:"); total_num2.setbounds(15, 298, 34, 16); rental_ret.add(total_num2); jtextfield total2 = new jtextfield(7); total2.setcolumns(10); total2.setbounds(109, 295, 116, 22); rental_ret.add(total2); jlabel payment_type2 = new jlabel("payment type:"); payment_type2.setbounds(15, 332, 86, 16); rental_ret.add(payment_type2); cc_button2 = new jradiobutton("credit card"); cc_button2.setbounds(109, 328, 93, 25); rental_ret.add(cc_button2); debit_button2 = new jradiobutton("debit"); debit_button2.setbounds(220, 326, 57, 25); rental_ret.add(debit_button2); buttongroup group2 = new buttongroup(); group2.add(debit_button); group2.add(cc_button); jlabel age2 = new jlabel("age: "); age2.setbounds(15, 112, 31, 16); rental_ret.add(age2); update_button = new button("update"); update_button.setbounds(15, 368, 83, 24); rental_ret.add(update_button); update_button.addactionlistener(this); jlabel agreement = new jlabel("agreement id: "); agreement.setbounds(15, 13, 93, 16); rental_ret.add(agreement); agreement_id = new jtextfield(); agreement_id.setcolumns(10); agreement_id.setbounds(109, 10, 116, 22); rental_ret.add(agreement_id); return_car = new button("return car"); return_car.setbounds(109, 368, 83, 24); rental_ret.add(return_car); return_car.addactionlistener(this); } public void actionperformed(actionevent action) { if(action.getsource() == submit_button){ try { mystatement.execute("insert customer (fname, lname, age, licnum, state, car_type, rentdate, returndate, total, paytype, returned) values('tony','mahan', 56,'s622-400-55-400-0', 'ak', 'a', '2016-04-07', '2016-04-10', 213.47, 'credit', true)"); } catch (sqlexception e) { // todo auto-generated catch block e.printstacktrace(); } } if(action.getsource() == load_button); if(action.getsource() == clear_button); if(action.getsource() == return_car); if(action.getsource() == update_button); } }
i not sure in insert command
mystatement.execute("insert customer (fname, lname, age, licnum, state, car_type, rentdate, returndate, total, paytype, returned) values('tony','mahan', 56,'s622-400-55-400-0', 'ak', 'a', '2016-04-07', '2016-04-10', 213.47, 'credit', true)");
if have defined returned field in database varchar think last value true
should in between ' '
-> 'true'
Comments
Post a Comment