求教。。。
本帖最后由 xingshen100 于 2013-10-18 21:43:52 编辑
package cn.itcast.demo;
//将大文本写入数据库
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.Reader;
import java.net.URL;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.junit.Test;
import cn.itcast.utils.JdbcUtils;
public class Demo1 {
/**
create database day15;
use day15;
create table testclob
(
id int primary key auto_increment,
resume text
);
*/
//操作大文本
@Test
public void add(){
Connection conn=null;
PreparedStatement st=null;
ResultSet rs=null;
try {
conn=JdbcUtils.getConnection();
String sql="insert into testclob(resume) values(?)";
st=conn.prepareStatement(sql);
String path=Demo1.class.getClassLoader().getResource("1.txt").getPath();
System.out.println("路径是" + path);
File file=new File(path);
st.setCharacterStream(1, new FileReader(file),(int)new File(path).length());//这里!!!
int num=st.executeUpdate();
if(num>0){
System.out.println("插入成功!");
}
} catch (Exception e) {
e.printStackTrace();
} finally{
JdbcUtils.release(conn, st, rs);
}
}
}
1.st.setCharacterStream(1, new FileReader(file),(int)file.length());
2.st.setCharacterStream(1, new FileReader(file));
程序中用第一句时,正确运行
用第二句时就报错了:
java.lang.AbstractMethodError: com.mysql.jdbc.PreparedStatement.setCharacterStream(ILjava/io/Reader;)V
at cn.itcast.demo.Demo1.add(Demo1.java:49)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.internal.runners.TestMethodRunner.executeMethodBody(TestMethodRunner.java:99)
at org.junit.internal.runners.TestMethodRunner.runUnprotected(TestMethodRunner.java:81)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
at org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75)
at org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45)
at org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:66)
at org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:35)
at org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
at org.eclipse.jdt.internal.junit.runne