Update MySQL database (java. SQL. SQLException: No value specified for parameter 1) exception solution,

Source: Internet
Author: User

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

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.