将数组中的对象插入sql

时间:2017-02-02 01:46:17

标签: java mysql

我的代码

public void commitContractor()
     {
         for (Contractor c: Contractor.contractorArray)
         {
             String dbHolder = "";
             dbHolder = "INSERT INTO SYSTEM.CONTRACTOR(CONTRACTORID, FIRSTTNAME, LASTNAME, MIDDLEINITIAL, HOUSENUMBER, STREET, CITYCOUNTY, STATEABB, COUNTRYABB, ZIPCODE, FEE, LASTUPDATEDBY, LASTUPDATED) VALUES(";
             dbHolder += c.getContractorID() + ", ";
             dbHolder += "'" + c.getFirstName() + "', ";
             dbHolder += "'" + c.getLastName() + ", ";
             dbHolder += "'" + c.getMiddleInitial() + "', ";
             dbHolder += c.getHouseNumber() + ", ";
             dbHolder += "'" + c.getStreet() + "', ";
             dbHolder += "'" + c.getCityCounty() + ", ";
             dbHolder += "'" + c.getStateAbb() + "', ";
             dbHolder += "'" + c.getCountryAbb() + ", ";
             dbHolder += c.getZipcode() + "', ";
             dbHolder += c.getFee() + ", ";
             dbHolder += "'" + c.getLastUpdatedBy() + "', to_date(";
             dbHolder += c.getLastUpdated() + "','yyyy-MM-dd'),')";

             System.out.println(dbHolder);

                sendDBCommand(dbHolder); // sends sql line to db
//                dbHolder = ""; 
         }
     }

在此结束

INSERT INTO SYSTEM.CONTRACTOR(CONTRACTORID, FIRSTTNAME, LASTNAME, MIDDLEINITIAL, HOUSENUMBER, STREET, CITYCOUNTY, STATEABB, COUNTRYABB, ZIPCODE, FEE, LASTUPDATEDBY, LASTUPDATED) VALUES(1000, 'gdgsd', 'gdsg, 'g', 345, 'gfsdg', 'gdgf, 'CA', 'IRL, 3453', 535.0, 'Taylor Bailey', to_date(2017-02-01','yyyy-MM-dd'),')

INSERT INTO SYSTEM.CONTRACTOR(CONTRACTORID, FIRSTTNAME, LASTNAME, MIDDLEINITIAL, HOUSENUMBER, STREET, CITYCOUNTY, STATEABB, COUNTRYABB, ZIPCODE, FEE, LASTUPDATEDBY, LASTUPDATED) VALUES(1000, 'gdgsd', 'gdsg, 'g', 345, 'gfsdg', 'gdgf, 'CA', 'IRL, 3453', 535.0, 'Taylor Bailey', to_date(2017-02-01','yyyy-MM-dd'),')
  

java.sql.SQLSyntaxErrorException:ORA-00917:缺少逗号

     

线程中的异常" JavaFX应用程序线程"显示java.lang.NullPointerException       在Lab1.CIS484Lab1.commitContractor(CIS484Lab1.java:316)       在Lab1.CIS484Lab1.lambda $ start $ 2(CIS484Lab1.java:244)       at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)       at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)       at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)       at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)       at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)       at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)       at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)       at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)       at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)       at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)       在com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)       在com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)       在javafx.event.Event.fireEvent(Event.java:198)       在javafx.scene.Node.fireEvent(Node.java:8411)       在javafx.scene.control.Button.fire(Button.java:185)       at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)       at com.sun.javafx.scene.control.skin.BehaviorSkinBase $ 1.handle(BehaviorSkinBase.java:96)       at com.sun.javafx.scene.control.skin.BehaviorSkinBase $ 1.handle(BehaviorSkinBase.java:89)       at com.sun.javafx.event.CompositeEventHandler $ NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)       at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)       at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)       at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)       at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)       at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)       at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)       at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)       at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)       at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)       at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)       在com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)       在com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)       在javafx.event.Event.fireEvent(Event.java:198)       在javafx.scene.Scene $ MouseHandler.process(Scene.java:3757)       在javafx.scene.Scene $ MouseHandler.access $ 1500(Scene.java:3485)       在javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)       在javafx.scene.Scene $ ScenePeerListener.mouseEvent(Scene.java:2494)       at com.sun.javafx.tk.quantum.GlassViewEventHandler $ MouseEventNotification.run(GlassViewEventHandler.java:380)       at com.sun.javafx.tk.quantum.GlassViewEventHandler $ MouseEventNotification.run(GlassViewEventHandler.java:294)       at java.security.AccessController.doPrivileged(Native Method)       at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda $ handleMouseEvent $ 354(GlassViewEventHandler.java:416)       at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)       at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:415)       在com.sun.glass.ui.View.handleMouseEvent(View.java:555)       在com.sun.glass.ui.View.notifyMouse(View.java:937)       at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)       at com.sun.glass.ui.win.WinApplication.lambda $ null $ 148(WinApplication.java:191)       在java.lang.Thread.run(Thread.java:745)

0 个答案:

没有答案