我用java连接数据库 上传blob限制文件大小 上传后的blob文件 用update方法也无法修改
PreparedStatement fileu=conn.prepareStatement("update tblob set tblob= ? where tid='try106'");
每次修改后不管参数是什么都变成null用2.0的结果集
( stat=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);)
也不能修改 提示读取专用的结果集不能修改谁知道应该怎样接解决呀~
PreparedStatement fileu=conn.prepareStatement("update tblob set tblob= ? where tid='try106'");
每次修改后不管参数是什么都变成null用2.0的结果集
( stat=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);)
也不能修改 提示读取专用的结果集不能修改谁知道应该怎样接解决呀~
System.out.println(rs.next());
System.out.println(rs.getString (1));
System.out.println(rs.getBlob(2).length());
rs.updateBinaryStream(2,in,2000);
rs.updateRow();<----异常
以上是用2.0的代码
以下是异常java.sql.SQLException: 读取专用的结果集不能修改 :updateBinaryStream
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:180)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:222)
at oracle.jdbc.driver.BaseResultSet.updateBinaryStream(BaseResultSet.java:279)
at temp.main(temp.java:100)
java.lang.AbstractMethodError: oracle.jdbc.driver.OracleConnection.createStatement(III)Ljava/sql/Statement;
at temp.main(temp.java:29)
Exception in thread "main"
import oracle.jdbc.*;
import oracle.jdbc.pool.*;
String strSql = "select content from text_content where id = ? for update" ;
ps = _conn.prepareStatement(strSql);
ps.setString(1,strID) ;
rset = ps.executeQuery();
while (rset.next())
{
CLOB web = ((OracleResultSet)rset).getCLOB(1) ;
Writer w = web.getCharacterOutputStream() ;
w.write("ssssssssssssssss") ;
w.flush() ;
w.close() ;
}
rset.close() ;
ps.close() ;clob 和 blob应该是一样的!
在各种情况下对blob进行处理是有区别的.
String url="jdbc:oracle:thin:@192.168.1.6:1521:mrdwh";
String user="system";
String password="manager";
conn= DriverManager.getConnection(url,user,password);
stat=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
这是代码 应该没有错误的吧 但是就是不能够修改结果集
private PooledConnection pc ;
public CreateConnectPool()
{
try
{
// Create a OracleConnectionPoolDataSource instance
ocpds = new OracleConnectionPoolDataSource();
// Set connection parameters
ocpds.setURL("jdbc:oracle:oci8:@mrdwh");
//ocpds.setDriverType("oci8");
//ocpds.setServerName("mrdwh");
//ocpds.setNetworkProtocol("tcp");
//ocpds.setDatabaseName("mrdwh");
//ocpds.setPortNumber(1521);
ocpds.setUser("system");
ocpds.setPassword("manager");
// Create a pooled connection
pc = ocpds.getPooledConnection();
}
catch( Exception e )
{
System.out.println(e.getMessage());
e.printStackTrace();
}
}
private Connection getConnection()
{
try
{
// Get a Logical connection
return pc.getConnection();
}
catch( Exception e )
{
System.out.println(e.getMessage());
e.printStackTrace();
return null ;
}
}
public void Connect()
{
conn = getConnection() ;
if(conn!=null)
{
System.out.println("Connection successful.");
}
} public void Disconnect()
{
try
{
conn.close();
conn = null ;
System.out.println("DisConnection successful.");
}
catch( Exception e )
{
System.out.println(e.getMessage());
e.printStackTrace();
}
}
而且加上也不知道 能不能改... 大虾们 有没有知道的呀
int bytesread = 0;
byte[] butter = new byte[8 * 1024];
java.io.ByteArrayOutputStream bos = null;
String sql = "";
java.sql.Blob blob = null;
sql = sqlblob[index] + ifwhere;
// System.out.println(sql);
//
// System.out.println(sql);
try {
//Initialization ByteArrayOutputStream
bos = new java.io.ByteArrayOutputStream();
//Get Connection
con = new DBconn().getConnection(); pst = con.prepareStatement(sql);
rs = pst.executeQuery();
int size = 0;
while (rs.next()) {
//Get Blob
blob = rs.getBlob(1);
if (blob != null && blob.length() != 0) {
is = blob.getBinaryStream();
while ( ( (bytesread = is.read()) != -1)) {
bos.write(bytesread);
} }
} }
catch (Exception e) {
System.out.println(e.toString());
}
finally {
try {
if (rs != null)
rs.close();
if (pst != null)
pst.close();
if (con != null)
con.close(); }
catch (Exception e) {
System.out.println("数据库连接错误:" + e.toString());
}
}
return bos;
}
myFile = new File(pathname);
try {
//将文件转化为文件流
java.io.FileInputStream fis = new FileInputStream(myFile);
//得到一个数据库连接
con = new DBconn().getConnection();
pst = con.prepareStatement("update test set mblob=? where id=2");
//pst.setInt(1,2);
byte bb[];
String sql = "ab";
bb = sql.getBytes();
pst.setBinaryStream(1, new java.io.ByteArrayInputStream(bb), bb.length);
//pst.setBinaryStream(1,fis,(int)myFile.length());
pst.executeUpdate();
}
catch (Exception e) {
System.out.println(e.toString());
}
finally {
try {
if (rs != null)
rs.close();
if (pst != null)
pst.close();
if (con != null)
con.close(); }
catch (Exception e) {
System.out.println(e.toString());
}
}
}
import oracle.sql.*;//for Oracle extensions to JDBC
import oracle.jdbc.pool.*;
import java.io.*;
import oracle.jdbc.*;
import oracle.jdbc.pool.*;
import oracle.jdbc2.*;
import oracle.sql.*;我都用了
我没用批处理但是用for update的时候 就会阻塞...
java.sql.SQLException: 无法操作: streams type cannot be used in batching
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:180)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:222)
at oracle.jdbc.driver.OraclePreparedStatement.addBatch(OraclePreparedStatement.java:3262)
at temp.main(temp.java:52)
{
public static void main(String[] args)
{ Connection conn;
Statement stat;
FileOutputStream out;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
String url="jdbc:oracle:thin:@192.168.1.6:1521:mrdwh";
String user="system";
String password="manager";
conn= DriverManager.getConnection(url,user,password);
stat=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
byte[] b=null;
byte[] bt=null;
File f= new File("d:/log.jpg");
System.out.println(f.length());
FileInputStream in= new FileInputStream (f);
b= new byte[(int)f.length()];
in.read(b);
in.close();
in= new FileInputStream (f);
conn.setAutoCommit(false);
PreparedStatement pst = conn.prepareStatement("update tblob set tblob=? where tid='try001' ");
byte bb[];
String sql = "ab";
bb = sql.getBytes();
pst.setBinaryStream(1,in,b.length);
pst.addBatch();
pst.executeBatch();
conn.commit();
conn.setAutoCommit(true);
}
catch (Exception e){
e.printStackTrace();
}
System.out.println("over");
}
上面的代码有错误吗?