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. Python之PIP安装

    Python有两个著名的包管理工具easy_install.py和pip.Python2.7的安装包中自带了easy_install.py,而pip需要手动安装.而在Python3.5之后都是默认安装 ...

  2. 设计模式——工厂方法(Factory Method)

    定义一个用于创建对象的接口,让子类决定实例化哪一个类.工厂方法使一个类的实例化延迟到其子类. ——DP UML类图 模式说明 抽象业务基类 实际业务类的公共基类,也是工厂要创建的所有对象的父类,这部分 ...

  3. python_sting字符串的方法及注释

    string类型是python内置的类型,无需安装   方法/属性 说明   capitalize()   把字符串的第一个字符改为大写   casefold()   把整个字符串的所有字符改为小写 ...

  4. C# 高级编程语言

    高级语言(High-level programming language)相对于机器语言(machine language,是一种指令集的体系.这种指令集,称机器码(machine code),是电脑 ...

  5. Linux系统的vim编辑器的配置文件的初步说明

    vim 编辑器的基本说明 vi编辑器的功能类似于Windows下的记事本,只能编辑普通文本,而vim编辑器则相当于Windows下的notepad++等高级编辑器,提升了代码开发效率. 将vi命令默认 ...

  6. AngularJs在ng-click函数中如何获取代表当前元素的DOM对象

    <!DOCTYPE html> <html> <head> <title></title> <script src="lib ...

  7. Redis Windows环境搭建

    简介 Redis是一个开源(BSD许可),内存存储的数据结构服务器,可用作数据库,高速缓存和消息队列代理.它支持字符串.哈希表.列表.集合.有序集合,位图,hyperloglogs等数据类型.内置复制 ...

  8. 介绍一个很好用的Rsa加解密的.Net库 Kalix.ApiCrypto

    Rsa非对称加密技术 这个就不说了,大家上网搜索都知道,公钥加密,私钥解密.当然大家也可以自己实现.这里就懒了,就去找一个现成的库,Nuget上搜索,GitHub上搜索,发现.Net的加解密库,下载量 ...

  9. jQuery读取和设定KindEditor值的方法

    转载自:https://www.jb51.net/article/43595.htm 侵删 jQuery读取和设定KindEditor值的方法 更新时间:2013年11月22日 09:03:56   ...

  10. [LeetCode]10. Regular Expression Matching正则表达式匹配

    Given an input string (s) and a pattern (p), implement regular expression matching with support for ...