1      Public Static voidMain (string[] args)throwsSQLException {223344 String driver= "Oracle.jdbc.driver.OracleDriver";55 String url= "Jdbc:oracle:thin: @www. Ee.w.www:1521:orcl"; 66 String user= "RRR"; 77 String password= "RRR";8899 Connection conn=NULL;TenTen PreparedStatement stmt=NULL; One11//Statement _stmt=null; AResultSet rs=NULL; -List<testentity> entitylist=NULL; -14Try { the15 -16Class.forName (driver); -conn=(Connection) drivermanager.getconnection (URL, user, password); -String sql= "SELECT * from T_daoshu_test where c_time>?"; +19//String _sql= "select Max (ID) from t_daoshu_test"; -20//_stmt= (Statement) conn.createstatement (); +stmt=(PreparedStatement) conn.preparestatement (SQL); AStmt.setobject (1,NewJava.sql.Timestamp (NewDate (). GetTime ())); atRs=stmt.executequery ();//_stmt.executequery (SQL); -entitylist=NewArraylist<testentity>(); -25intI=0; -26 while(Rs.next ()) -27             { -I=rs.getint (1); in29             }     -30 to31/*While (Rs.next ()) + { - testentity en=new testentity (); the En.setid (Rs.getint ("ID")); * En.setarea (rs.getstring ("C_area")); $ En.settype (rs.getstring ("C_type"));Panax Notoginseng Panax Notoginseng en.settitle (rs.getstring ("C_title")); - En.setlink (rs.getstring ("C_link")); the en.setdate (Rs.getdate ("C_time")); + entitylist.add (en); A  A the  **/ +SYSTEM.OUT.PRINTLN ("Max ID:" +i); -SYSTEM.OUT.PRINTLN ("Set Size:" +entitylist.size ()); $45 $46}Catch(ClassNotFoundException e) { -47e.printstacktrace (); -48}finally the49         { -50Closeresource (rs,stmt,conn);Wuyi51 the52         } -53 Wu54 -55if(Entitylist.size () >0) About56         {     $57//Inserting Data -58Try { -59Class.forName (driver); -conn=(Connection) drivermanager.getconnection (URL, user, password); ASql= String "INSERT into t_form_210 (work_flow_process_id, Create_time, work_flow_id, Node_value, Unite_ State, COL0, COL1, COL2, COL3, COL4, COL5) ";  +sql+= "VALUES ( -1, Sysdate,-1,-1,-1,?,?,?,?,?,?)"; the63 -Conn.setautocommit (false); $PreparedStatement pst=(PreparedStatement) conn.preparestatement (SQL); the66 for(intI=0;i<entitylist.size (); i++) the67                 { theTestentity entity=Newtestentity (); theentity=Entitylist.get (i); -Pst.setstring (1, Entity.gettype ()); inPst.setstring (2, Entity.getarea ()); thePst.setstring (3, Entity.gettitle ()); thePst.setstring (4, Entity.getlink ()); AboutPst.setobject (5,NewJava.sql.Timestamp (NewDate (). GetTime ()));//Update Time thePst.setobject (6,NewJava.sql.Timestamp (NewDate (). GetTime ()));//Last update Time the76Pst.addbatch ();  the77                 }     +78//Perform a batch update -79Pst.executebatch (); the80conn.commit ();BayiBayi System.out.println (NewJava.sql.Timestamp (NewDate (). GetTime ()) + "synchronized data"); the82}Catch(ClassNotFoundException e) { the83e.printstacktrace (); -84}finally -85             { the86Closeresource (rs,stmt,conn); the87 the88             } the89 -90         } the91 the         Public Static voidCloseresource (ResultSet rs,statement stmt,connection conn) the {94         if(rs!=NULL) the         { the             Try { the rs.close ();98}Catch(SQLException e) { About                 //TODO auto-generated Catch block - e.printstacktrace ();101             }102         }    103         if(stmt!=NULL)104         { the             Try {106 stmt.close ();107}Catch(SQLException e) {108                 //TODO auto-generated Catch block109 e.printstacktrace (); the             }111         }     the         if(conn!=NULL)113         { the             Try { the conn.close (); the}Catch(SQLException e) {117                 //TODO auto-generated Catch block118 e.printstacktrace ();119             } -         }    121         122}
JDBC Inserts data into Oracle