📄 sqlbean.java
字号:
package cn.edu.ujn.srms.pub.conn;
import java.io.PrintStream;
import java.sql.*;
import java.util.StringTokenizer;
// Referenced classes of package ISEBeans.conn:
// DBManager
public class SQLBean
{
private static DBManager connMgr = DBManager.getInstance();
private static String sDBDriver;
private static ResultSet spRs = null;
Connection conn;
ResultSet rs;
Statement stmt;
private PreparedStatement prepstmt;
boolean autoCommit;
public SQLBean()
throws Exception
{
conn = null;
rs = null;
stmt = null;
prepstmt = null;
conn = null;
rs = null;
stmt = null;
conn = connMgr.getConnection("SchDB");
}
public Connection getConn()
{
return conn;
}
public static String getDriverName()
{
return sDBDriver;
}
public void callSp(String s)
throws Exception
{
CallableStatement callablestatement = conn.prepareCall(s);
callablestatement.execute();
}
public ResultSet callSpReturnRs(String s, int i, String s1)
throws Exception
{
conn.setAutoCommit(false);
ResultSet resultset = null;
if(sDBDriver.toLowerCase().indexOf("kingbase") >= 0)
{
String s2 = String.valueOf(String.valueOf((new StringBuffer("begin :1 := cap.")).append(s).append("(")));
StringTokenizer stringtokenizer = new StringTokenizer(s1, ",");
int l = 1;
Object obj = null;
while(stringtokenizer.hasMoreTokens())
{
String s5 = stringtokenizer.nextToken();
s2 = String.valueOf(String.valueOf((new StringBuffer(String.valueOf(String.valueOf(s2)))).append(s5).append(",")));
l++;
}
s2 = s2.substring(0, s2.length() - 1);
s2 = String.valueOf(String.valueOf(s2)).concat("); end;");
CallableStatement callablestatement2 = conn.prepareCall(s2);
callablestatement2.registerOutParameter(1, -10);
callablestatement2.execute();
resultset = (ResultSet)callablestatement2.getObject(1);
} else
if(sDBDriver.toLowerCase().indexOf("jsqldriver") >= 0)
{
String s3 = String.valueOf(String.valueOf((new StringBuffer("{call ")).append(s).append("(")));
for(int j = 1; j <= i; j++)
{
s3 = String.valueOf(String.valueOf(s3)).concat("?,");
}
s3 = s3.substring(0, s3.length() - 1);
s3 = String.valueOf(String.valueOf(s3)).concat(")}");
CallableStatement callablestatement = conn.prepareCall(s3);
StringTokenizer stringtokenizer1 = new StringTokenizer(s1, ",");
int i1 = 1;
Object obj1 = null;
for(int k1 = 1; k1 <= i; k1++)
{
String s6 = stringtokenizer1.nextToken();
if(s6 == null || s6.equals("''"))
{
callablestatement.setString(i1, "");
} else
{
callablestatement.setString(i1, s6);
}
i1++;
}
resultset = callablestatement.executeQuery();
} else
if(sDBDriver.toLowerCase().indexOf("openbase") >= 0)
{
String s4 = String.valueOf(String.valueOf((new StringBuffer("{call ")).append(s).append("(")));
for(int k = 1; k <= i; k++)
{
s4 = String.valueOf(String.valueOf(s4)).concat("?,");
}
s4 = s4.substring(0, s4.length() - 1);
s4 = String.valueOf(String.valueOf(s4)).concat(")}");
System.out.print("CallableStatement=" + s4);
CallableStatement callablestatement1 = conn.prepareCall(s4, 1004, 1008);
StringTokenizer stringtokenizer2 = new StringTokenizer(s1, ",");
int j1 = 1;
String s7 = null;
for(int l1 = 1; l1 <= i; l1++)
{
s7 = stringtokenizer2.nextToken();
if(s7 == null || s7.equals("''"))
{
callablestatement1.setString(j1, "");
} else
{
callablestatement1.setString(j1, s7);
}
j1++;
}
System.out.print(" para=" + s7 + "\r\n");
resultset = callablestatement1.executeQuery();
System.out.print("Stored Procedure Executed!");
}
return resultset;
}
public Connection conn()
throws Exception
{
conn = null;
conn = connMgr.getConnection("SchDB");
return conn;
}
public void executeUpdate(String s)
throws Exception
{
stmt = conn.createStatement(1003, 1008);
stmt.executeUpdate(s);
}
public ResultSet executeQuery(String s)
throws Exception
{
rs = null;
stmt = conn.createStatement(1004, 1008);
rs = stmt.executeQuery(s);
return rs;
}
public ResultSet executeQueryRd(String s)
throws Exception
{
rs = null;
stmt = conn.createStatement(1004, 1007);
rs = stmt.executeQuery(s);
return rs;
}
public ResultSet executeQueryForFiles(String s)
throws Exception
{
rs = null;
stmt = conn.createStatement(1003, 1008);
rs = stmt.executeQuery(s);
return rs;
}
public ResultSet getModule(String s, String s1, int i)
{
String s2 = null;
ResultSet resultset1;
try
{
String s3 = sDBDriver.toLowerCase();
if(s3.indexOf("kingbase") >= 0)
{
s2 = String.valueOf(String.valueOf((new StringBuffer("select a.func_id,a.func_name,a.weight,a.height,a.url_link,a.icon_path from func_" +
"spec a, (select distinct substr(func_id,1,"
)).append(i).append(") func_id from func_user_func where user_id = '").append(s).append("' and func_id like '").append(s1).append("%') b where a.func_id = b.func_id")));
} else
if(s3.indexOf("openbase") >= 0)
{
s2 = String.valueOf(String.valueOf((new StringBuffer("select a.func_id,a.func_name,a.weight,a.height,a.url_link,a.icon_path from func_" +
"spec a, (select distinct substr(func_id,1,"
)).append(i).append(") func_id from func_user_func where user_id = '").append(s).append("' and func_id like '").append(s1).append("%') b where a.func_id = b.func_id")));
} else
if(s3.indexOf("jsqldriver") >= 0)
{
s2 = String.valueOf(String.valueOf((new StringBuffer("select a.func_id,a.func_name,a.weight,a.height,a.url_link,a.icon_path from func_" +
"spec a, (select distinct left(func_id,"
)).append(i).append(") func_id from func_user_func where user_id = '").append(s).append("' and func_id like '").append(s1).append("%') b where a.func_id = b.func_id")));
} else
if(s3.indexOf("sybase") >= 0)
{
s2 = String.valueOf(String.valueOf((new StringBuffer("select a.func_id,a.func_name,a.weight,a.height,a.url_link,a.icon_path from func_" +
"spec a, (select distinct left(func_id,"
)).append(i).append(") func_id from func_user_func where user_id = '").append(s).append("' and func_id like '").append(s1).append("%') b where a.func_id = b.func_id")));
}
stmt = conn.createStatement(1004, 1007);
ResultSet resultset = stmt.executeQuery(s2);
return resultset;
}
catch(Exception exception)
{
resultset1 = null;
}
return resultset1;
}
public void prepareStatement(String s)
throws SQLException
{
prepstmt = conn.prepareStatement(s);
}
public void prepareStatement(String s, int i, int j)
throws SQLException
{
prepstmt = conn.prepareStatement(s, i, j);
}
public void setString(int i, String s)
throws SQLException
{
prepstmt.setString(i, s);
}
public void setInt(int i, int j)
throws SQLException
{
prepstmt.setInt(i, j);
}
public void setBoolean(int i, boolean flag)
throws SQLException
{
prepstmt.setBoolean(i, flag);
}
public void setDate(int i, Date date)
throws SQLException
{
prepstmt.setDate(i, date);
}
public void setLong(int i, long l)
throws SQLException
{
prepstmt.setLong(i, l);
}
public void setFloat(int i, float f)
throws SQLException
{
prepstmt.setFloat(i, f);
}
public void setBytes(int i, byte abyte0[])
throws SQLException
{
prepstmt.setBytes(i, abyte0);
}
public void clearParameters()
throws SQLException
{
prepstmt.clearParameters();
prepstmt = null;
}
public PreparedStatement getPreparedStatement()
{
return prepstmt;
}
public Statement getStatement()
{
return stmt;
}
public void executeUpdate()
throws SQLException
{
if(prepstmt != null)
{
prepstmt.executeUpdate();
}
}
public ResultSet executeQuery()
throws SQLException
{
if(prepstmt != null)
{
return prepstmt.executeQuery();
} else
{
return null;
}
}
public void beginTrans() throws SQLException
{ try
{
autoCommit=conn.getAutoCommit();
conn.setAutoCommit(false);
}
catch(SQLException ex)
{
ex.printStackTrace();
System.out.print("beginTrans Errors");
throw ex;
}
}
public void commit() throws SQLException
{
try
{
conn.commit();
conn.setAutoCommit(autoCommit);
}
catch(SQLException ex)
{
ex.printStackTrace();
System.out.print("Commit Errors");
throw ex;
}
}
public void rollback()
{
try
{
conn.rollback();
conn.setAutoCommit(autoCommit);
}
catch(SQLException ex)
{
ex.printStackTrace();
System.out.print("Rollback Errors");
//throw ex;
}
}
public boolean getAutoCommit() throws SQLException
{
boolean result=false;
try
{
result=conn.getAutoCommit();
}
catch(SQLException ex)
{
ex.printStackTrace();
System.out.println("getAutoCommit fail"+ex.getMessage());
throw ex;
}
return result;
}
public void close()
throws SQLException
{
if(stmt != null)
{
stmt.close();
stmt = null;
}
if(prepstmt != null)
{
prepstmt.close();
prepstmt = null;
}
if(conn != null)
{
connMgr.freeConnection("SchDB", conn);
conn = null;
}
}
static
{
sDBDriver = DBManager.FirstDriverName;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -