更新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 ...
随机推荐
- onbeforeunload与onunload事件
Onunload,onbeforeunload都是在刷新或关闭时调用,可以在<script>脚本中通过 window.onunload来指定或者在<body>里指定.区别在于o ...
- selenium框架安装及webdriver安装
本文介绍的是selenium安装及webdriver安装.小实例 1.selenium介绍 selenium是一个用于web应用程序测试的工具. Selenium测试直接运行在浏览器,就向真正的用户操 ...
- UVALive 7500 Boxes and Balls 2015EC final 签到题 二分
分析题目后,得到要求的是最接近n的一个数,并且这个数字能写成1+2+3+....+x = ans这种形式. 要求的是最大的值. 这题就直接二分去做吧.二分出一个f(mid)<=n的最大值. 最后 ...
- 用命令行的方式将本地项目上传到git
1.(先进入项目文件夹)通过命令 git init 把这个目录变成git可以管理的仓库 git init 2.把文件添加到版本库中,使用命令 git add .添加到暂存区里面去,不要忘记后面的小数点 ...
- System path '/Users/hxy/Library/Caches/PyCharm2018.2' is invalid.
Mac系统下安装pycharm后启动出现System path '/Users/hxy/Library/Caches/PyCharm2018.2' is invalid.问题: 1.出现原因: 1.1 ...
- 子元素的margin-top会影响父元素
---恢复内容开始--- 之前在写项目的时候,发现原本想让父子元素之间加点边距,却让父元素产生了margin-top,于是百度之后发现了原因. 在css2.1盒模型中 In this specific ...
- Web框架的应用
从今天开始,我们将要学习有关Web框架的一些内容,在学习之前先来学习一下http协议,即基于http是如何通信的. http 概要:http是基于tcp/ip通信协议来传输数据的. 优点: 1.简单快 ...
- js的内联和外部调用
如上代码(实现轮播图的部分代码),若以内联形式写在html里,就不会出现异常.但是如果放在外部js文件中,并在html的head中调用,就会出现异常(不报错,但是轮播逻辑出现异常). 解决:不使用全局 ...
- echarts折线图相关
optionJKDLine = { title: { text: '告警数量趋势图', textStyle:{ //标题样式 fontStyle:'normal', fontFamily:'sans- ...
- Css文件目录结构
一般一个网站会有这么三个样式: global.css | reset.css(格式化样式) common.css(公共组件样式) layout.css(当前页面样式) global.css | res ...