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(jsonResult, 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));//图片的URL地址截图成图片名称后更新数据库
ps.setInt(2, id);
}
ps.executeUpdate();
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
DBUtil.closeAll(conn, ps, null);
}
}
}

更新数据库url字段出错

修改代码如下:

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(jsonResult, 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();
System.out.println(str);
int id=result.get(i).getId();
if (str != null && str.length() > 0) {
int number=str.lastIndexOf("/")+1;
System.out.println(number);
String change=str.substring(number);
System.out.println(change);
ps.setString(1, change);
ps.setInt(2, id);
ps.addBatch();
}
}
ps.executeBatch();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
DBUtil.closeAll(conn, ps, null);
}
}
}

更新MySQL数据库( java.sql.SQLException: No value specified for parameter 1) 异常 解决方法的更多相关文章

  1. 【MySQL】java.sql.SQLException: The server time zone value

    错误:Could not open JDBC Connection for transaction; nested exception is java.sql.SQLException: The se ...

  2. 【MySQL】java.sql.SQLException: Incorrect string value: '\xF0\x9F\x98\xB3' for column

    问题原因: 输入内容包含特殊字符,MySQL 中的列不支持. 解决方法 多数是修改 MySQL 的数据库和表结构,CHARSET 改为 utf8mb4,但本人测试还是不能传入 emoji. 后来在代码 ...

  3. java.lang.NoClassDefFoundError: org/apache/commons/io/output/DeferredFileOutputStream异常解决方法

    使用Tomcat部署Servlet程序时,单步调试跟踪到: List<FileItem> itemList = sfu.parseRequest(request); 总是会报错:Java. ...

  4. 【转】Caused by: java.lang.NoClassDefFoundError: android.support.v7.gridlayout.R$dimen 异常解决方法

    在使用gridlayout中遇到 Caused by: java.lang.NoClassDefFoundError: android.support.v7.gridlayout.R$dimen 问题 ...

  5. java.lang.IllegalArgumentException: java.util.zip.ZipException: invalid LOC header (bad signature)异常解决方法

    java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start com ...

  6. mysql: java.sql.SQLException: Incorrect string value: '\xF0\x9F\x92\x90</...'

    插入数据出现问题,因为包含了特殊字符. 现象: 插入的数据中如果含有某些特殊字符,会导致插入数据失败,例如字符串”测试**插入数据...“,在console中insert是正常的,但是使用java代码 ...

  7. 问题:java.sql.SQLException: No value specified for parameter 1

    解决方案:没有指定参数 String user = req.getParameter("user"); String pwd = req.getParameter("pw ...

  8. java.sql.SQLException: Could not retrieve transaction read-only status from server 问题解决

    网上有2种主要说法 第一种 问题描述: java代码在开始事务后,先做了一个查询,再insert,此时会报:          java.sql.SQLException: could not ret ...

  9. struts2+hibernate+spring简单整合且java.sql.SQLException: No suitable driver 问题解决

    最近上j2ee的课,老师要求整合struts2+hibernate+spring,我自己其实早早地有准备弄的,现在都第9个项目了,无奈自己的思路和头绪把自己带坑了,当然也是经验问题,其实只是用myec ...

随机推荐

  1. AT2382 A or...or B Problem

    传送门 还是看题解的啦 先考虑一个显而易见的结论:A和B二进制下最高的几位相同是没用的(设去掉的那些位之和为sum) 然后我们设\(d\)为二进制下从高位到低位第一位不相同的,\(k\)为B从高位到低 ...

  2. javascript的模块发展

    谨以此文记录了解js模块的过程 随着ES6的出现,js模块已经成为正式的标准了.曾经为了解决js模块问题而发展起来的民间秘籍,requireJs(AMD).SeaJs(CMD).Node(Common ...

  3. CSS(一)清除浮动

    问题1:关于清除浮动 <!DOCTYPE html> <html lang="en"> <head> <meta charset=&quo ...

  4. Python网络爬虫(二)

    Urllib库之解析链接 Urllib库里有一个parse这个模块,定义了处理URL的标准接口,实现 URL 各部分的抽取,合并以及链接转换.它支持如下协议的 URL 处理:file.ftp.goph ...

  5. 装饰器(Decorator)模式

    public interface IDoThings { public void doSomeThing(); } public class DoThings implements IDoThings ...

  6. Solve Equations HackerRank 扩展欧几里德 && 数学

    https://www.hackerrank.com/contests/infinitum16-firsttimer/challenges/solve-equations 给定一条方程a*x + b* ...

  7. SpringBoot | 番外:使用小技巧合集

    前言 最近工作比较忙,事情也比较多.加班回到家都十点多了,洗个澡就想睡觉了.所以为了不断更太多天,偷懒写个小技巧合集吧.之后有时间都会进行文章更新的.原创不易,码字不易,还希望大家多多支持!话不多说, ...

  8. maven安装,使用说明,及maven Repository如何使用.

    maven的使用方法总结一下 1.首先去apache官网下载maven, http://maven.apache.org/download.cgi2.如果是windows系统,选择 apache-ma ...

  9. 最简实例演示asp.net5中用户认证和授权(1)

    asp.net5中,关于用户的认证和授权提供了非常丰富的功能,如果结合ef7的话,可以自动生成相关的数据库表,调用也很方便. 但是,要理解这么一大堆关于认证授权的类,或者想按照自己项目的特定要求对认证 ...

  10. 开发原则&设计模式

    1.关于软件开发中的开发原则和设计模式: 1.1.开发原则 1.1.1.什么是开发原则? 开发原则就是开发的依据,只要依照这些原则进行开发,将来开发的软件具有很强的扩展力,很低的耦合度. 开发原则不属 ...