jdbc问题
publicclassBlobTest{publicstaticvoidmain(String[]args)throwsSQLException,IOException{...
public class BlobTest { public static void main(String[] args) throws SQLException, IOException {
create();
}
static void create() throws SQLException, IOException{
//存储大文本,即将javautils。java存储到数据库中去,利用字符流把文本串放到数据库中去
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);
File file=new File("1.jpg");
InputStream in=new BufferedInputStream(new FileInputStream(file));//reader是字符流,InputStream字节流
//上面都是javaseIo流的基础
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);
}
}}
出现异常:
Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '燄玛軣戸\\S劎叀啠O?邍揾?费酷$歴eㄞn|??Lg?
Ud?S?c阚蝧 Sぎ?陭' at line 1
哪位大侠指点一下! 展开
create();
}
static void create() throws SQLException, IOException{
//存储大文本,即将javautils。java存储到数据库中去,利用字符流把文本串放到数据库中去
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);
File file=new File("1.jpg");
InputStream in=new BufferedInputStream(new FileInputStream(file));//reader是字符流,InputStream字节流
//上面都是javaseIo流的基础
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);
}
}}
出现异常:
Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '燄玛軣戸\\S劎叀啠O?邍揾?费酷$歴eㄞn|??Lg?
Ud?S?c阚蝧 Sぎ?陭' at line 1
哪位大侠指点一下! 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询