📄 reportdaoimpl.java
字号:
;
Debug.println("[ReportDAOImpl]dellReportBuildDataPage--->>>sql:" +
sql);
stmt.executeUpdate(sql);
// conn.commit();
flag = true;
}
catch (SQLException sqle) {
Debug.println(
"[ReportDAOImpl]dellReportBuildDataPage--->>>Exception:" +
sqle.getMessage());
}
finally {
try {
this.closePreparedStatement();
}
catch (Exception e) {
}
try {
this.closeResultSet();
}
catch (Exception e) {
}
try {
this.closeStatement();
}
catch (Exception e) {
}
try {
this.closeConnection();
}
catch (Exception e) {
}
}
return flag;
}
/**
* 删除报表数据 report_code
*应用:删除报表数据[UNIVERSAL_REPORT_DATA]
*/
public boolean dellReportBuildDataReportCode(String report_code) throws
AppException {
boolean flag = false;
String sql = null;
try {
conn = Common.getConnection();
// conn.setAutoCommit(false);
stmt = conn.createStatement();
//是否正常数据
if (report_code == null || "".equals(report_code)) {
Debug.println(
"[ReportDAOImpl]dellReportBuildDataReportCode----->report_code is null!");
return flag;
}
/*
code
page_code
content 内容
*/
sql = "delete from "
+ TableNameUtil.UNIVERSAL_REPORT_DATA
+ " where report_code='"
+ PubFunc.toSql(report_code, 0)
+ "'"
;
Debug.println("[ReportDAOImpl]dellReportBuildDataReportCode--->>>sql:" +
sql);
stmt.executeUpdate(sql);
// conn.commit();
flag = true;
}
catch (SQLException sqle) {
Debug.println(
"[ReportDAOImpl]dellReportBuildDataReportCode--->>>Exception:" +
sqle.getMessage());
}
finally {
try {
this.closePreparedStatement();
}
catch (Exception e) {
}
try {
this.closeResultSet();
}
catch (Exception e) {
}
try {
this.closeStatement();
}
catch (Exception e) {
}
try {
this.closeConnection();
}
catch (Exception e) {
}
}
return flag;
}
/**
* 得到表关键字段的sn
*应用:修改生成形成报表记录数据
*/
private String getTableSN(String tableName, String fieldCode) throws
AppException {
boolean flag = false;
String sql = null;
String tableSN = "10000001";
int intPar = 0;
try {
conn = Common.getConnection();
// conn.setAutoCommit(false);
stmt = conn.createStatement();
//是否正常数据
if (tableName == null || "".equals(tableName)) {
Debug.println(
"[ReportDAOImpl]getTableSN----->tableName is null!");
return tableSN;
}
sql = "select "
+ fieldCode
+ " from "
+ tableName
+ " order by "
+ fieldCode
+ " desc"
;
Debug.println("[ReportDAOImpl]getTableSN--->>>sql:" + sql);
rs = stmt.executeQuery(sql);
if (rs.next()) {
tableSN = rs.getString(fieldCode);
long i = 0;
i = Long.parseLong(tableSN) + 1;
tableSN = "" + i;
Debug.println(
"[ReportDAOImpl]getTableSN--->>> tableSN:" +
tableSN);
}
else {
Debug.println(
"[ReportDAOImpl]getTableSN--->>>not record,return " +
tableSN);
return tableSN;
}
// conn.commit();
flag = true;
}
catch (Exception sqle) {
Debug.println("[ReportDAOImpl]getTableSN--->>>Exception:" +
sqle.getMessage());
}
finally {
try {
this.closePreparedStatement();
}
catch (Exception e) {
}
try {
this.closeResultSet();
}
catch (Exception e) {
}
try {
this.closeStatement();
}
catch (Exception e) {
}
try {
this.closeConnection();
}
catch (Exception e) {
}
}
return tableSN;
}
/*
* Method that calls update stored procedure on the database. This will use
* the getCLOB method() and oracle.sql.CLOB class to create the CLOB object
* before passing it to the procedure.
* http://otn.oracle.com/sample_code/tech/java/codesnippet/jdbc/lob/TestClob.java.html
*/
public void callUpdate(String id, String filename, Connection conn) throws
SQLException {
CallableStatement cs = null;
CLOB clob = null;
String clobData = null;
try {
// Read the file whose content has to be updated in the CLOB column.
String lineSep = System.getProperty("line.separator");
BufferedReader br = new BufferedReader(new FileReader(filename));
String nextLine = "";
StringBuffer sb = new StringBuffer();
while ( (nextLine = br.readLine()) != null) {
sb.append(nextLine);
sb.append(lineSep);
}
// Convert the content to string.
clobData = sb.toString();
// call Stored DB procedure for updating CLOB column.
cs = (CallableStatement)
conn.prepareCall("begin updateStory(?,?); end;");
// create the CLOB object
clob = getCLOB(clobData, conn);
// set id
cs.setObject(1, id);
//set clob data
cs.setObject(2, clob);
// Execute callable statement.
cs.execute();
// Close the Statement object
cs.close();
}
catch (SQLException ex) {
Debug.println("SQLException status : " + ex.getMessage());
}
catch (Exception ex) {
Debug.println("some exception " + ex.getMessage());
}
finally {
try {
// Close Statement
if (cs != null) {
cs.close();
}
// Free CLOB
if (clob != null) {
clob.freeTemporary();
}
// Close connection
if (conn != null) {
conn.close();
}
}
catch (Exception ex) {
Debug.println(
"Some exception in callUpdate method of given "
+ "status : " + ex.getMessage());
}
}
}
/*
* This method creates CLOB object using temporary clob and returns the same.
* http://otn.oracle.com/sample_code/tech/java/codesnippet/jdbc/lob/TestClob.java.html
*/
public String getContent(String clobData,Connection connn)throws Exception{
String s_content = "";
PreparedStatement pstate = connn.prepareStatement(clobData);
ResultSet rs = pstate.executeQuery();
if(rs.next()){
s_content = rs.getString("content");
}
return s_content;
}
public CLOB getCLOB(String clobData, Connection connn) throws Exception {
CLOB tempClob = null;
try {
// create a new temporary CLOB
CLOB.createTemporary(connn, true, CLOB.DURATION_SESSION);
Debug.println("1");
tempClob = CLOB.createTemporary(connn, true, CLOB.DURATION_SESSION);
Debug.println("2");
// Open the temporary CLOB in readwrite mode to enable writing
tempClob.open(CLOB.MODE_READWRITE);
// Get the output stream to write
Writer tempClobWriter = tempClob.getCharacterOutputStream();
// Write the data into the temporary CLOB
tempClobWriter.write(clobData);
// Flush and close the stream
tempClobWriter.flush();
tempClobWriter.close();
// Close the temporary CLOB
tempClob.close();
}
catch (Exception exp) {
exp.printStackTrace();
tempClob.freeTemporary();
Debug.println("Exception thrown in getCLOB method "
+ "of given status : "
+ exp.getMessage());
}
return tempClob;
}
/*
* This method uses CallableStatement.setAsciiStream() method to stream
* the clob data to the procedure within the callable statement.
* http://otn.oracle.com/sample_code/tech/java/codesnippet/jdbc/lob/TestClob.java.html
*/
public void callUpdateUsingStream(String id, String filename) throws
SQLException, FileNotFoundException {
CallableStatement cs = null;
try {
// conn.setAutoCommit(false);
String fileName = filename;
// Open the sample file as a stream
File file = new File(fileName);
FileInputStream fin = new FileInputStream(file);
// Call Stored DB procedure for updating clob column
cs = (CallableStatement)
conn.prepareCall("begin updateStory(?,?); end;");
// set id.
cs.setObject(1, id);
// set the clob parameter using setAsciiStream method.
cs.setAsciiStream(2, fin, (int) file.length());
cs.execute();
// conn.setAutoCommit(true);
}
catch (SQLException sqlex) {
Debug.println("SQLException in callUpdateUsingStream method " +
" of given status : " + sqlex.getMessage());
}
catch (FileNotFoundException fnex) {
Debug.println(
"FileNotFoundException in callUpdateUsingStream method " +
" of given status : " + fnex.getMessage());
}
finally {
try {
// Close Statement
if (cs != null) {
cs.close();
}
// Close connection.
if (conn != null) {
conn.close();
}
}
catch (Exception ex) {
Debug.println(
"Some exception in callUpdateUsingStream method " +
" of given status : " + ex.getMessage());
}
}
}
/**
*Close the PreparedStatement.
* @param none
* @return none
* @exception SQLException
*/
protected void closePreparedStatement() throws AppException {
try {
if (pstmt != null) {
pstmt.close();
}
Debug.print("pstmt已关闭:" + pstmt);
}
catch (SQLException sqle) {
Debug.println(
"[reportDAOimpl]closeConnection=============SQLException=" + sqle);
AppException le = new AppException( (Exception) sqle);
throw le;
}
}
/**
*Close the Statement.
* @param st
* @return none
* @exception SQLException
*/
protected void closeStatement() throws AppException {
try {
if (this.stmt != null) {
stmt.close();
}
}
catch (SQLException sqle) {
Debug.println(
"[reportDAOimpl]closeConnection=============SQLException=" + sqle);
AppException le = new AppException( (Exception) sqle);
throw le;
}
}
/**
*Close the resultset.
* @param st
* @return none
* @exception SQLException
*/
protected void closeResultSet() throws AppException {
try {
if (rs != null) {
rs.close();
}
}
catch (SQLException sqle) {
Debug.println(
"[reportDAOimpl]closeConnection=============SQLException=" + sqle);
AppException le = new AppException( (Exception) sqle);
throw le;
}
}
/**
*Close the connection.
* @param none
* @return none
* @exception SQLException
*/
protected void closeConnection() throws AppException {
try {
if (conn != null && !conn.isClosed()) {
conn.close();
}
Debug.print("conn已关闭:" + conn);
}
catch (SQLException sqle) {
Debug.println(
"[reportDAOimpl]closeConnection=============SQLException=" + sqle);
AppException le = new AppException( (Exception) sqle);
throw le;
}
}
public static void main(String[] args) {
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -