Update MySQL database (java. SQL. SQLException: No value specified for parameter 1) exception solution,
Package com. swift; import java. io. file; import java. SQL. connection; import java. SQL. preparedStatement; import java. SQL. SQLException; import java. util. list; import com. google. gson. gson; public class UpdateUrl {public static void main (String [] args) {File file = new File ("D: \ java_date", "questionJson. json "); String jsonResult = GetData. getData (file); Gson gson = new Gson (); Root root = gson. fromJson (json Result, Root. class); List <Result> result = root. getResult (); updateUrl (result);} private static void updateUrl (List <Result> result) {Connection conn = DBUtil. getConn (); PreparedStatement ps = null; try {ps = conn. prepareStatement ("update sw_question set url =? Where id = ?) "); For (int I = 0; I <result. size (); I ++) {String str = result. get (I ). getUrl (); int id = result. get (I ). getId (); if (str! = Null & str. length ()> 0) {ps. setString (1, str. substring (str. lastIndexOf ("/") + 1); // update the database ps after the URL of the image is the image name. setInt (2, id);} ps.exe cuteUpdate () ;}} catch (SQLException e) {// TODO Auto-generated catch block e. printStackTrace ();} finally {DBUtil. closeAll (conn, ps, null );}}}
Solution to SQL Exception error when updating database URL content