更新MySQL数据库( java.sql.SQLException: No value specified for parameter 1) 异常 解决方法
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) 异常 解决方法的更多相关文章
- 【MySQL】java.sql.SQLException: The server time zone value
错误:Could not open JDBC Connection for transaction; nested exception is java.sql.SQLException: The se ...
- 【MySQL】java.sql.SQLException: Incorrect string value: '\xF0\x9F\x98\xB3' for column
问题原因: 输入内容包含特殊字符,MySQL 中的列不支持. 解决方法 多数是修改 MySQL 的数据库和表结构,CHARSET 改为 utf8mb4,但本人测试还是不能传入 emoji. 后来在代码 ...
- java.lang.NoClassDefFoundError: org/apache/commons/io/output/DeferredFileOutputStream异常解决方法
使用Tomcat部署Servlet程序时,单步调试跟踪到: List<FileItem> itemList = sfu.parseRequest(request); 总是会报错:Java. ...
- 【转】Caused by: java.lang.NoClassDefFoundError: android.support.v7.gridlayout.R$dimen 异常解决方法
在使用gridlayout中遇到 Caused by: java.lang.NoClassDefFoundError: android.support.v7.gridlayout.R$dimen 问题 ...
- java.lang.IllegalArgumentException: java.util.zip.ZipException: invalid LOC header (bad signature)异常解决方法
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start com ...
- mysql: java.sql.SQLException: Incorrect string value: '\xF0\x9F\x92\x90</...'
插入数据出现问题,因为包含了特殊字符. 现象: 插入的数据中如果含有某些特殊字符,会导致插入数据失败,例如字符串”测试**插入数据...“,在console中insert是正常的,但是使用java代码 ...
- 问题:java.sql.SQLException: No value specified for parameter 1
解决方案:没有指定参数 String user = req.getParameter("user"); String pwd = req.getParameter("pw ...
- java.sql.SQLException: Could not retrieve transaction read-only status from server 问题解决
网上有2种主要说法 第一种 问题描述: java代码在开始事务后,先做了一个查询,再insert,此时会报: java.sql.SQLException: could not ret ...
- struts2+hibernate+spring简单整合且java.sql.SQLException: No suitable driver 问题解决
最近上j2ee的课,老师要求整合struts2+hibernate+spring,我自己其实早早地有准备弄的,现在都第9个项目了,无奈自己的思路和头绪把自己带坑了,当然也是经验问题,其实只是用myec ...
随机推荐
- Jmeter_拦截Excel文件输出流到本地
一般而言,对于页面的“导出”操作,主要经历如下两个操作:①根据数据库的内容,将文件导出到应用服务器上:②将服务器上的文件下载到本地电脑: Jmeter同LoadRunner类似,只能记录服务端与客户端 ...
- 4、kvm相关网卡操作(添加、删除)
查看虚拟机的网卡信息 virsh domiflist privi-server 添加临时网卡 virsh attach-interface privi-server --type bridge --s ...
- Composite模式(组合设计模式)
Composite 设计模式? 在计算机的文件系统中,有"文件夹"的概念(在有些操作系统(Linux操作系统)中,也称为"目录").文件夹里面既可以放入文件,也 ...
- SerializeUtil
import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.ObjectInpu ...
- Domain Model
VO(View Object):视图对象,用于展示层,它的作用是把某个指定页面(或组件)的所有数据封装起来. DTO(Data Transfer Object):数据传输对象,这个概念来源于J2EE的 ...
- TortoiseSVN 搭建本地版本库及简单操作使用
TortoiseSVN是windows上一款著名的版本控制软件,对于我们管理自己的代码,特别是对一个团队来说,非常重要. 本文探讨的是如何搭建本地的版本库. (1)安装TortoiseSVN之后需要创 ...
- python+selenium之多窗口切换
#打开浏览器driver = webdriver.Firefox()driver.get(url)#获取当前窗口now_handle=driver.current_window_handle # 获取 ...
- 整理:sql server 中sql语句执行顺序
SQL Server 查询处理中的各个阶段(SQL执行顺序) SQL 不同于与其他编程语言的最明显特征是处理代码的顺序.在大数编程语言中,代码按编码顺序被处理,但是在SQL语言中,第一个被处理的子句是 ...
- aspx有"记住我"的登录
客户端 <form id="form1" runat="server"> <div> 用户名:<input type=" ...
- Java中的for循环——通过示例学习Java编程(9)
作者:CHAITANYA SINGH 来源:https://www.koofun.com/pro/kfpostsdetail?kfpostsid=21 循环用于反复执行同一组语句,直到满足特定条件 ...