向mysql插入一个longtext对象,文件大小为968B,插进去却是933B? 怎么个情况?读出来是不完整的,最后少一段 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 package com.etoak;import java.io.File;import java.io.FileInputStream;import java.io.FileReader;import java.io.InputStream;import java.io.Reader;import java.sql.*;public class WriteMySQL { public static void main(String[] args){ // create table test(b longblob,t longtext); ConnFactory conn = null; //ConnFactory是一个连接数据库的工厂类 Connection con = null; PreparedStatement ps = null; String sql = "insert into test values(?,?)"; try{ conn = ConnFactory.newInstance(); con = conn.getConnection("mysql"); ps = con.prepareStatement(sql); File file = new File("E:\\图片\\3.jpg"); InputStream is = new FileInputStream(file); int len = (int)file.length(); ps.setBinaryStream(1,is,len); File file2 = new File("E:\\day and day\\game.java"); Reader reader = new FileReader(file2); int len2 = (int)file2.length();System.out.println(len2); ps.setCharacterStream(2,reader,len2); ps.execute(); reader.close(); is.close(); }catch(Exception e){ e.printStackTrace(); }finally{ conn.close(con,ps,null); } }} 数据库字符排序问题 Mysql 视频分享 将SQLSER数据用DTS导入到MYSQL中遇到问题急 mysql两天数据字段拼接 在线等 急急急 mysql 索引的使用 让我郁闷的mysql Windows 2003下的ERROR 2003: Can't connect to MySQL server on 'localhost' (10061) 关于数据库表设计的问题 mysql 的存储过程的问题 MySQL Cluster备份方案 遇到mysql case when 问题 关于MYSQL多条件查询orderby优化的问题
package com.etoak;import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.InputStream;
import java.io.Reader;
import java.sql.*;public class WriteMySQL {
public static void main(String[] args){
// create table test(b longblob,t longtext);
ConnFactory conn = null; //ConnFactory是一个连接数据库的工厂类
Connection con = null;
PreparedStatement ps = null;
String sql = "insert into test values(?,?)";
try{
conn = ConnFactory.newInstance();
con = conn.getConnection("mysql");
ps = con.prepareStatement(sql);
File file = new File("E:\\图片\\3.jpg");
InputStream is = new FileInputStream(file);
int len = (int)file.length();
ps.setBinaryStream(1,is,len);
File file2 = new File("E:\\day and day\\game.java");
Reader reader = new FileReader(file2);
int len2 = (int)file2.length();System.out.println(len2);
ps.setCharacterStream(2,reader,len2);
ps.execute();
reader.close();
is.close();
}catch(Exception e){
e.printStackTrace();
}finally{
conn.close(con,ps,null);
}
}
}