PackageCom.swift;ImportJava.io.File;Importjava.sql.Connection;Importjava.sql.PreparedStatement;Importjava.sql.SQLException;Importjava.util.List;ImportCom.google.gson.Gson; Public classUpdateUrl { Public Static voidMain (string[] args) {File file=NewFile ("D:\\java_date", "Questionjson.json"); String Jsonresult=getdata.getdata (file); Gson Gson=NewGson (); Root root= Gson.fromjson (Jsonresult, Root.class); List<Result> Result =Root.getresult (); UpdateUrl (result); } Private Static voidUpdateUrl (list<result>result) {Connection conn=Dbutil.getconn (); PreparedStatement PS=NULL; Try{PS= Conn.preparestatement ("update sw_question set url =?") where id=?) "); for(inti = 0; I < result.size (); i++) {String str=Result.get (i). GETURL (); intId=Result.get (i). GetId (); if(str! =NULL&& str.length () > 0) {ps.setstring (1, str.substring (Str.lastindexof ("/") +1) ;//The URL of the picture is the name of the image after updating the database Ps.setint (2, id); } ps.executeupdate (); } } Catch(SQLException e) {//TODO auto-generated Catch blockE.printstacktrace (); } finally{dbutil.closeall (conn, PS,NULL); } }}
Workaround for SQL Exception error when updating database URL contents
Update MySQL Database (java.sql.SQLException:No value specified for parameter 1) exception workaround