📄 stabstractdataset.java
字号:
package com.stsc.util;
import java.io.*;
import java.sql.*;
import java.util.*;
import oracle.jdbc.OracleResultSet;
import oracle.sql.BLOB;
// Referenced classes of package com.stsc.util:
// STResultSet
public abstract class STAbstractDataSet
{
protected int TotalCount;
protected int ReturnCount;
protected Connection conn;
protected Statement stmt;
protected ResultSet rs;
public STAbstractDataSet()
{
TotalCount = 0;
ReturnCount = 0;
conn = null;
stmt = null;
rs = null;
}
protected abstract Connection getConnection(Properties properties)
throws Exception;
public boolean close()
{
log("Close Connection...");
boolean flag = true;
try
{
if(rs != null)
{
rs.close();
rs = null;
}
}
catch(Exception exception)
{
flag = false;
log("STDataSet.close() error:Cannot close resultset." + exception);
}
try
{
if(stmt != null)
{
stmt.close();
stmt = null;
}
}
catch(Exception exception1)
{
flag = false;
log("STDataSet.close() error:Cannot close statement." + exception1);
}
try
{
if(conn != null && !conn.isClosed())
{
conn.close();
conn = null;
}
}
catch(Exception exception2)
{
flag = false;
log("STDataSet.close() error:Cannot close connection." + exception2);
}
return flag;
}
protected void dispose()
{
close();
}
protected void finalize()
{
}
public int getTotalCount()
{
return TotalCount;
}
public int getReturnCount()
{
return ReturnCount;
}
public ResultSet getResult(String s, Properties properties)
{
try
{
if(conn == null)
conn = getConnection(properties);
if(conn == null)
throw new Exception("无法创建数据库连接。");
if(stmt == null)
stmt = conn.createStatement();
rs = stmt.executeQuery(s.trim());
return rs;
}
catch(Exception exception)
{
log("STDataSet.getResult() error:" + exception);
}
return null;
}
public ResultSet getPageResult(String s, Properties properties, int i, int j)
{
try
{
String s1 = s.trim();
if(!s1.toUpperCase().startsWith("SELECT "))
throw new Exception("本函数只能用于SELECT 查询语句。");
int k = s1.toUpperCase().indexOf("FROM");
if(k < 0)
throw new Exception("SQL查询语句错误,没有找到FROM关键字。");
String s4 = s1.substring(k);
String s5 = "SELECT COUNT(*) " + s4;
if(conn == null)
conn = getConnection(properties);
if(conn == null)
throw new Exception("无法创建数据库连接。");
if(stmt == null)
stmt = conn.createStatement();
log(s5);
rs = stmt.executeQuery(s5);
if(rs.next())
TotalCount = rs.getInt(1);
rs.close();
if(TotalCount == 0 && !s1.toUpperCase().startsWith("SELECT COUNT("))
return null;
if(i > 0 && j > 0)
{
String s3 = "SELECT * FROM (select MY_TEMPTABLE.*,ROWNUM AS MY_TEMPID from (" + s1 + ") MY_TEMPTABLE ) WHERE MY_TEMPID <= " + String.valueOf(i * j) + " AND MY_TEMPID>" + String.valueOf((i - 1) * j);
String s2 = "SELECT COUNT(*) FROM (select MY_TEMPTABLE.*,ROWNUM AS MY_TEMPID from (" + s1 + ") MY_TEMPTABLE ) WHERE MY_TEMPID <= " + String.valueOf(i * j) + " AND MY_TEMPID>" + String.valueOf((i - 1) * j);
log(s3);
log(s2);
rs = stmt.executeQuery(s2);
if(rs.next())
ReturnCount = rs.getInt(1);
rs.close();
if(ReturnCount == 0)
{
return null;
} else
{
rs = stmt.executeQuery(s3);
return rs;
}
} else
{
ReturnCount = TotalCount;
log(s1);
rs = stmt.executeQuery(s1);
return rs;
}
}
catch(Exception exception)
{
log("STDataSet.getPageResult() error:" + exception);
exception.printStackTrace();
return null;
}
}
public boolean executeSQL(String s, Properties properties)
{
Exception exception;
boolean flag;
try
{
if(conn == null)
conn = getConnection(properties);
if(conn == null)
throw new Exception("无法创建数据库连接。");
if(stmt == null)
stmt = conn.createStatement();
log("executeSQL: " + s);
int i = stmt.executeUpdate(s);
flag = true;
}
finally
{
dispose();
}
return flag;
exception;
log("STDataSet.executeSQL(String,dbBase) error:\n" + exception + "\n " + s);
exception.printStackTrace();
flag = false;
return flag;
}
public boolean executeSQL(Vector vector, Properties properties)
{
boolean flag;
Exception exception;
boolean flag1;
Exception exception1;
boolean flag2;
boolean flag3;
try
{
if(vector != null && vector.size() != 0)
break MISSING_BLOCK_LABEL_18;
flag = true;
}
finally
{
dispose();
}
return flag;
if(conn == null)
conn = getConnection(properties);
if(conn == null)
throw new Exception("无法创建数据库连接。");
conn.setAutoCommit(false);
if(stmt != null)
stmt.close();
stmt = conn.createStatement();
String s = "";
for(int i = 0; i < vector.size(); i++)
{
String s1 = (String)vector.get(i);
log("executeSQL: " + s1);
stmt.addBatch(s1);
}
int ai[] = stmt.executeBatch();
conn.commit();
flag3 = true;
return flag3;
exception1;
log("STDataSet.executeSQL(Vector,Properties) error:\n" + exception1 + "\n" + vector);
exception1.printStackTrace();
conn.rollback();
flag2 = false;
return flag2;
local;
stmt.close();
stmt = null;
if(conn != null)
conn.setAutoCommit(true);
JVM INSTR ret 9;
exception;
log("STDataSet.executeSQL(Vector,Properties) error:\n" + exception + "\n" + vector);
exception.printStackTrace();
flag1 = false;
return flag1;
}
private void log(String s)
{
s = "======" + (new Date()).toString() + "======\n " + s;
System.out.println(s);
}
public STResultSet getSTResult(String s, Properties properties)
{
ResultSet resultset = getResult(s, properties);
STResultSet stresultset = new STResultSet(resultset);
dispose();
return stresultset;
}
public STResultSet getPageSTResult(String s, Properties properties, int i, int j)
{
ResultSet resultset = getPageResult(s, properties, i, j);
STResultSet stresultset = new STResultSet(resultset);
dispose();
return stresultset;
}
public boolean updateBlob(String s, String s1, String as[], String as1[], InputStream inputstream, Properties properties)
{
boolean flag;
Exception exception;
boolean flag1;
BLOB blob;
boolean flag2;
boolean flag3;
boolean flag4;
try
{
if(s != null && !s.trim().equals(""))
break MISSING_BLOCK_LABEL_31;
log("STDataSet.updateBlob() : 表名不能为空值。");
flag = false;
}
finally
{
try
{
conn.setAutoCommit(true);
}
catch(Exception exception2) { }
dispose();
}
return flag;
if(s1 != null && !s1.trim().equals(""))
break MISSING_BLOCK_LABEL_62;
log("STDataSet.updateBlob() : 内容字段名不能为空值。");
flag = false;
return flag;
if(as != null && as1 != null)
break MISSING_BLOCK_LABEL_86;
log("STDataSet.updateBlob() : 关键字段名或值不能为空值。");
flag = false;
return flag;
if(inputstream != null)
break MISSING_BLOCK_LABEL_106;
log("STDataSet.updateBlob() : 内容为空值。");
flag = false;
return flag;
if(as.length == as1.length)
break MISSING_BLOCK_LABEL_129;
log("STDataSet.updateBlob() : 关键字段列表和值列表不匹配。");
flag = false;
return flag;
if(as.length != 0)
break MISSING_BLOCK_LABEL_149;
log("STDataSet.updateBlob() : 必须有关键字段才能执行。");
flag = false;
return flag;
if(conn == null)
conn = getConnection(properties);
if(conn == null)
throw new Exception("无法创建数据库连接。");
conn.setAutoCommit(false);
if(stmt == null)
stmt = conn.createStatement();
String s2 = "";
for(int i = 0; i < as.length; i++)
{
if(i == 0)
s2 = s2 + " WHERE ";
else
s2 = s2 + " AND ";
s2 = s2 + as[i] + "='" + as1[i] + "'";
}
String s3 = "UPDATE " + s + " SET " + s1 + "=empty_blob() " + s2;
stmt.executeUpdate(s3);
conn.commit();
s3 = "SELECT " + s1 + " FROM " + s;
s3 = s3 + s2 + " FOR UPDATE";
rs = stmt.executeQuery(s3);
if(!rs.next())
break MISSING_BLOCK_LABEL_652;
blob = ((OracleResultSet)rs).getBLOB(1);
if(blob == null)
{
String s4 = "UPDATE " + s + " SET " + s1 + "=empty_blob() " + s2;
stmt.executeUpdate(s4);
rs = stmt.executeQuery(s3);
blob = ((OracleResultSet)rs).getBLOB(1);
}
if(blob != null)
break MISSING_BLOCK_LABEL_594;
log("STDataSet.updateBlob() : 无法更新该BLOB字段。");
flag3 = false;
return flag3;
OutputStream outputstream = blob.getBinaryOutputStream();
int j = blob.getChunkSize();
for(byte abyte0[] = new byte[j]; inputstream.read(abyte0) != -1; outputstream.write(abyte0, 0, j));
outputstream.close();
flag4 = true;
return flag4;
log("STDataSet.updateBlob() : 未找到需要更新的记录");
flag2 = false;
return flag2;
exception;
log("STDataSet.updateBlob() error:" + exception);
exception.printStackTrace();
flag1 = false;
return flag1;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -