当我运行是他总是提示这个错误,求大神帮忙解答.
以下是代码:
package com.heima.dao;
import java.io.FileInputStream;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.Scanner;
import com.heima.util.JdbcUtil;
public class UpdatePhoto {
@SuppressWarnings("resource")
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int count = 0;
while (count < 4) {
System.out.println("请输入需要修改联系人的名字(貂蝉,猪八戒,周瑜,小白,关羽,翠花,白居易,李白,全智贤): ");
String nameString = scanner.nextLine();
System.out.println("请输入联系人的头像(白居易,美女,李白,全智贤,法拉利,翠花,关羽): ");
String photoName = scanner.nextLine();
//定义sql语句
String sql = "update contact set photo=? where name=?";
Connection connection = null;
PreparedStatement ps = null;
try {
FileInputStream fs = new FileInputStream("images/" + photoName + ".jpg");
connection = JdbcUtil.getConnection();
ps = connection.prepareStatement(sql);
ps.setBlob(1, fs);
ps.setString(2, nameString);
int row = ps.executeUpdate();
System.out.println("向数据库中更新了" + row + "数据...");
fs.close();
count++;
System.out.println("还需要添加头像吗???(Y/N): ");
String lineString = scanner.nextLine();
if ("Y".equalsIgnoreCase(lineString)) {
continue;
}else if ("N".equalsIgnoreCase(lineString)) {
break;
}
} catch (Exception e) {
e.printStackTrace();
} finally{
JdbcUtil.closeAll(connection, ps);
}
count = 0;
}
}
}
|
|