that corresponds to your MySQL server version for the right syntax to use near '??X?±?Y÷%???s???;?>xKwSàE???u:???X“_u×A\0?d4I?d?‘??希望大家帮忙解决下。
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.InputStream;
import java.io.Reader;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;public class BlobTest { /**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
creat();
} //创建数据
static void creat() throws Exception{
//为了确保conn一定会被关闭,那么就把conn放在finally里面
Connection conn=null;
PreparedStatement ps =null;
ResultSet rs=null;
try {
//2.建立连接
conn=JdbcUtils.getConnection();
//利用单例的方法建立连接,(不建议用这种方式,太麻烦)
//conn=JdbcUtilsSing.getInstance().getConnection();
//3.创建语句
String sql="insert into blob_test(big_bit)values(?)";
ps=conn.prepareStatement(sql);
//第一种方法需要确认文件里面只有asscll码,不能有中文
File file=new File("4.gif");
InputStream in=new BufferedInputStream(new FileInputStream(file));
//setBinaryStream二进制输入流
ps.setBinaryStream(1,in,(int)file.length());
//4.执行语句
int i= ps.executeUpdate();//返回的是一个整型数字
in.close();
//5.处理结果
System.out.println("i="+i);
}finally{
JdbcUtils.free(rs, ps, conn);
}
}}
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.InputStream;
import java.io.Reader;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;public class BlobTest { /**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
creat();
} //创建数据
static void creat() throws Exception{
//为了确保conn一定会被关闭,那么就把conn放在finally里面
Connection conn=null;
PreparedStatement ps =null;
ResultSet rs=null;
try {
//2.建立连接
conn=JdbcUtils.getConnection();
//利用单例的方法建立连接,(不建议用这种方式,太麻烦)
//conn=JdbcUtilsSing.getInstance().getConnection();
//3.创建语句
String sql="insert into blob_test(big_bit)values(?)";
ps=conn.prepareStatement(sql);
//第一种方法需要确认文件里面只有asscll码,不能有中文
File file=new File("4.gif");
InputStream in=new BufferedInputStream(new FileInputStream(file));
//setBinaryStream二进制输入流
ps.setBinaryStream(1,in,(int)file.length());
//4.执行语句
int i= ps.executeUpdate();//返回的是一个整型数字
in.close();
//5.处理结果
System.out.println("i="+i);
}finally{
JdbcUtils.free(rs, ps, conn);
}
}}
这一行出现乱码了?语句没写错呀。
还是检查sql语句吧