从事数据库工作多年,目前看好分布式NeSQL/HTAP数据库在企业客户市场的发展。未来的主要方向是——致力于 NewSQL/HTAP 数据库的推广普及。
分类: Sybase
2013-05-15 16:21:50
package net.db.test;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Statement;
public class JDBCDemo {
private static final String DRIVER = "com.sybase.jdbc3.jdbc.SybDriver";
private static final String URL = "jdbc:sybase:Tds:192.168.0.197:6000/tpchdb?CHARSET=cp936&TEXTSIZE=2147483647"; //OK
public JDBCDemo() {
}
private byte[] getFileContent(String filename) {
try {
File file = new File(filename);
int length = (int)file.length();
InputStream input = new FileInputStream(filename);
byte[] content = new byte[length];
input.read(content, 0, length);
return content;
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
public void insert() throws Exception {
Connection con = this.getConnection(DRIVER, URL, "DBA", "sql");
String filename = "ccrmiq.rar";
String sqlString = "insert into test_blob (id,content) values(?,?)";
PreparedStatement pstmt = con.prepareStatement(sqlString);
pstmt.setInt(1,1000);
pstmt.setBytes(2, this.getFileContent(filename));
int state = pstmt.executeUpdate();
this.closeConnection(con, pstmt);
}
public static void main(String[] args) {
JDBCDemo demo = new JDBCDemo();
try {
demo.insert();
//demo.select();
//demo.delete();
} catch (Exception e) {
e.printStackTrace();
}
}
private Connection getConnection(String driver, String url, String user,
String password) throws Exception {
Class.forName(driver);
return DriverManager.getConnection(url, user, password);
}
private void closeConnection(Connection con, Statement stmt)
throws Exception {
if (stmt != null) {
stmt.close();
}
if (con != null) {
con.close();
}
}
}
在执行上面的java程序时再现了问题。
通过查找相关资料,最终的解决方法如下:
(1) 设置jConnect连接属性TEXTSIZE=2147483647
(2) 使用DBA用户登陆IQ,做如下设置:
set option public.ENABLE_LOB_VARIABLES='ON'