JDBC的成批更新问题,无法成批更新。求救 看了看没发现问题,特意试了试,也没问题有点区别是我用的com.mysql.jdbc.Driver 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你把那些Exception粘出来,我看了一下也没有什么问题。 给你一个我写的,和你的功能差不多,但是没问题。import java.io.*;import java.util.*;import java.sql.*;public class BlobColumn { public static void main(String[] args) { String driver = "org.gjt.mm.mysql.Driver"; String url = "jdbc:mysql://localhost:3306/test"; String user = "root"; String password = "roger"; Vector stream=null; stream=new Vector(); try { Class.forName(driver); } catch(ClassNotFoundException e) { System.out.println("ClassNotFoundException ->"+e); } try { Connection conn = DriverManager.getConnection(url, user, password); PreparedStatement pstmt = conn.prepareStatement("INSERT INTO friend VALUES(?,?,?)"); try { //String path="D:\\book\\photo\\"; //String path="D:\\pictrue\\美女精华\\"; String path="D:/pictrue/girl/"; File d=new File(path);//建立当前目录中文件的File对象 File list[]=d.listFiles();//取得代表目录中所有文件的File对象数组 for(int i=0;i<list.length;i++) { if(list[i].isFile()) { String FileName=list[i].getName(); InputStream fin = new FileInputStream(path+FileName); int length = (int) fin.available(); System.out.println("FileName ->"+FileName+" Size ->"+length); stream.add(fin); pstmt.setString(1,FileName); pstmt.setBinaryStream(2,fin,length); pstmt.setDouble(3,length); pstmt.addBatch(); } } } catch (Exception e) { System.out.println("IOException ->"+e); } int[] res=pstmt.executeBatch(); // pstmt.clearParameters(); pstmt.close(); for (int i=0;i<stream.size();i++) { try { InputStream in=(InputStream)stream.get(i); in.close(); } catch (Exception e) { System.out.println("close exception ->"+e); } } /* fin.close(); // 從資料庫取出檔案 Statement stmt = conn.createStatement(); ResultSet result = stmt.executeQuery("SELECT * FROM picture"); result.next(); String description = result.getString(1); Blob blob = result.getBlob(2); System.out.println("blob length ->"+(int)blob.length()); // 寫入檔案 System.out.println("檔案描述:" + description); FileOutputStream fout = new FileOutputStream("girl_2.jpg"); fout.write(blob.getBytes(1, (int)blob.length())); fout.flush(); fout.close(); */ // conn.close(); } catch(Exception e) { System.out.println("SQLException ->"+e); } }} 重复运行同一个java程序,需要复制多份程序到不同文件夹吗? 急急急!!java怎么实现图片拖拽功能? 如何把一个获得的整数变成负数~ 编程学习方法 JDBCF问题 char变量可以保存一个汉字么? 讨论:java软件的界面问题! swing程序独立运行要如何配置环境 求助:数据库问题 java工作可能会问些什么问题? 一个生产者消费者的一个线程互斥的程序,不知道为什么运行时会有错误 applet运行机制的简单问题
import java.io.*;
import java.util.*;
import java.sql.*;
public class BlobColumn
{
public static void main(String[] args)
{
String driver = "org.gjt.mm.mysql.Driver";
String url = "jdbc:mysql://localhost:3306/test";
String user = "root";
String password = "roger";
Vector stream=null;
stream=new Vector();
try
{
Class.forName(driver);
}
catch(ClassNotFoundException e)
{
System.out.println("ClassNotFoundException ->"+e);
}
try
{
Connection conn = DriverManager.getConnection(url, user, password);
PreparedStatement pstmt = conn.prepareStatement("INSERT INTO friend VALUES(?,?,?)");
try
{
//String path="D:\\book\\photo\\";
//String path="D:\\pictrue\\美女精华\\";
String path="D:/pictrue/girl/";
File d=new File(path);//建立当前目录中文件的File对象
File list[]=d.listFiles();//取得代表目录中所有文件的File对象数组
for(int i=0;i<list.length;i++)
{
if(list[i].isFile())
{
String FileName=list[i].getName();
InputStream fin = new FileInputStream(path+FileName);
int length = (int) fin.available();
System.out.println("FileName ->"+FileName+" Size ->"+length);
stream.add(fin);
pstmt.setString(1,FileName);
pstmt.setBinaryStream(2,fin,length);
pstmt.setDouble(3,length);
pstmt.addBatch();
}
}
}
catch (Exception e)
{
System.out.println("IOException ->"+e);
}
int[] res=pstmt.executeBatch();
// pstmt.clearParameters();
pstmt.close();
for (int i=0;i<stream.size();i++)
{
try
{
InputStream in=(InputStream)stream.get(i);
in.close();
}
catch (Exception e)
{
System.out.println("close exception ->"+e);
}
}
/* fin.close();
// 從資料庫取出檔案
Statement stmt = conn.createStatement();
ResultSet result = stmt.executeQuery("SELECT * FROM picture");
result.next();
String description = result.getString(1);
Blob blob = result.getBlob(2);
System.out.println("blob length ->"+(int)blob.length());
// 寫入檔案
System.out.println("檔案描述:" + description);
FileOutputStream fout = new FileOutputStream("girl_2.jpg");
fout.write(blob.getBytes(1, (int)blob.length()));
fout.flush();
fout.close(); */
// conn.close();
}
catch(Exception e)
{
System.out.println("SQLException ->"+e);
}
}
}