JSON code driver's License questions batch join MySQL database ps.executeupdate () always only sad to add a piece of data to remove the ID primary key auto-increment for and foreach

Source: Internet
Author: User
Tags addall

 PackageCom.swift;ImportJava.io.BufferedReader;ImportJava.io.File;ImportJava.io.FileInputStream;Importjava.io.FileNotFoundException;Importjava.io.IOException;ImportJava.io.InputStreamReader;Importjava.io.UnsupportedEncodingException;Importjava.sql.Connection;Importjava.sql.PreparedStatement;Importjava.sql.SQLException;Importjava.util.List;ImportCom.google.gson.Gson; Public classAddAll {/*** The JSON driver test code in the Jzkt.json file under the D-drive D:\java_JDK\java_date path is parsed into the root object using Gson*/     Public Static voidMain (string[] args) {File file=NewFile ("D:\\java_jdk\\java_date", "Jzkt.json"); StringBuilder SB=NULL; List<Result> list =NULL; Try{bufferedreader br=NewBufferedReader (NewInputStreamReader (NewFileInputStream (file), "Utf-8")); String Str=NULL; SB=NewStringBuilder (); FinalString line_separator = System.getproperty ("Line.separator"); Try {                 while(str = br.readline ())! =NULL) {sb.append (str);                Sb.append (Line_separator); } Gson Gson=NewGson (); Root root= Gson.fromjson (Sb.tostring (), Root.class); List= Root.getresult ();//gets the object list collection for the result type}Catch(IOException e) {e.printstacktrace (); }        } Catch(unsupportedencodingexception e) {e.printstacktrace (); } Catch(FileNotFoundException e) {e.printstacktrace (); }        if(AddAll (list)) {System.out.println ("Add Success"); } Else{System.out.println ("Add Failed"); }    }    Private Static BooleanAddAll (list<result>list) {Connection conn=Jdbcutil.getconn (); PreparedStatement PS=NULL; Try{PS= Conn.preparestatement ("INSERT into sw_question values (?,?,?,?,?,?,?,?,?)");  for(inti = 0; I < list.size (); i++) {//do not use the Foreach method, the query can be modified noSystem.out.println ("i=" +i); Ps.setint (1, List.get (i). GetId ()); Ps.setstring (2, List.get (i). Getquestion ()); Ps.setstring (3, List.get (i). Getanswer ()); Ps.setstring (4, List.get (i). GETITEM1 ()); Ps.setstring (5, List.get (i). GETITEM2 ()); Ps.setstring (6, List.get (i). GETITEM3 ()); Ps.setstring (7, List.get (i). GETITEM4 ()); Ps.setstring (8, List.get (i). Getexpalins ()); Ps.setstring (9, List.get (i). GETURL ()); Ps.addbatch ();//add to batch, use Ps.executeupdate () always only sad to add a piece of data} ps.executebatch ();//perform batch processing            return true; } Catch(SQLException e) {e.printstacktrace (); } finally{jdbcutil.closeall (conn, PS,NULL); }        return false; }}

JSON code driver's License questions batch join MySQL database ps.executeupdate () always only sad to add a piece of data to remove the ID primary key auto-increment for and foreach

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.