📄 oradbutil.java
字号:
package com.webpublish.dbutil;
import java.io.InputStream;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
public class OradbUtil extends DBConnection {
public java.sql.Connection conn = null; // connection object
public ResultSet rs = null; // resultset object
public Statement stmt = null; // statement object
public PreparedStatement prepstmt = null; // preparedstatement object
/**
* init()
*/
public OradbUtil() {
try {
this.conn = DBConnection.getConnOracle();
// db statement init
this.stmt = conn.createStatement(
java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,
java.sql.ResultSet.CONCUR_READ_ONLY);
} catch (Exception e) {
System.out.println("OradbUtillxd: init error!" + e.toString());
}
}
public OradbUtil(String SqlStr) {
try {
this.conn = DBConnection.getConnOracle();
// db statement init
this.prepstmt = conn.prepareStatement(SqlStr);
} catch (Exception e) {
System.out.println("OradbUtil: init error!" + e.toString());
}
}
public OradbUtil(String connServer, String dbUser, String dbPassword) {
try {
this.conn = DBConnection.getConnOracle(connServer, dbUser,
dbPassword);
// db statement init
this.stmt = conn.createStatement(
java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,
java.sql.ResultSet.CONCUR_READ_ONLY);
System.out.println("OradbUtil build");
} catch (Exception e) {
System.out.println("OradbUtilxiao: init error!" + e.toString());
}
}
public OradbUtil(String SqlStr, String connStr) {
try {
this.conn = DBConnection.getConnOracle(connStr, "db66user",
"cbznw68j");
// db statement init
this.prepstmt = conn.prepareStatement(SqlStr);
} catch (Exception e) {
System.out.println("OradbUtil: init error!" + e.toString());
}
}
/**
* @function prepareStatement
* @param sql
* String
* @throws SQLException
*/
public void prepareStatement(String sql) throws SQLException {
prepstmt = conn.prepareStatement(sql);
}
/**
* @function prepareStatement
* @param sql
* String
* @param resultSetType
* int
* @param resultSetConcurrency
* int
* @throws SQLException
*/
public void prepareStatement(String sql, int resultSetType,
int resultSetConcurrency) throws SQLException {
prepstmt = conn.prepareStatement(sql, resultSetType,
resultSetConcurrency);
}
/**
* @function executeQuery
* @param sql
* String
* @throws SQLException
* @return ResultSet
*/
public ResultSet executeQuery(String sql) throws SQLException {
if (stmt != null) {
return stmt.executeQuery(sql);
} else
return null;
}
/**
* @function executeQuery
* @throws SQLException
* @return ResultSet
*/
public ResultSet executeQuery() throws SQLException {
if (prepstmt != null) {
return prepstmt.executeQuery();
} else
return null;
}
/**
* @function executeUpdate
* @param sql
* String
* @throws SQLException
*/
public void executeUpdate(String sql) throws SQLException {
if (stmt != null)
stmt.executeUpdate(sql);
}
/**
* @function executeUpdate
* @throws SQLException
*/
public void executeUpdate() throws SQLException {
if (prepstmt != null)
prepstmt.executeUpdate();
}
/**
* @function executeUpdate
* @throws SQLException
*/
public void executeBatch() throws SQLException {
if (prepstmt != null)
prepstmt.executeBatch();
}
/**
* @function addBatch
* @param value
* String
* @throws SQLException
*/
public void addBatch(String value) throws SQLException {
prepstmt.addBatch(value);
}
/**
* @function setString
* @param index
* int
* @param value
* String
* @throws SQLException
*/
public void setString(int index, String value) throws SQLException {
prepstmt.setString(index, value);
}
/**
* @function setInt
* @param index
* int
* @param value
* int
* @throws SQLException
*/
public void setInt(int index, int value) throws SQLException {
prepstmt.setInt(index, value);
}
/**
* @function setBoolean
* @param index
* int
* @param value
* boolean
* @throws SQLException
*/
public void setBoolean(int index, boolean value) throws SQLException {
prepstmt.setBoolean(index, value);
}
/**
* @function setDate
* @param index
* int
* @param value
* Date
* @throws SQLException
*/
public void setDate(int index, Date value) throws SQLException {
prepstmt.setDate(index, value);
}
/**
* @function setLong
* @param index
* int
* @param value
* long
* @throws SQLException
*/
public void setLong(int index, long value) throws SQLException {
prepstmt.setLong(index, value);
}
/**
* @function setFloat
* @param index
* int
* @param value
* float
* @throws SQLException
*/
public void setFloat(int index, float value) throws SQLException {
prepstmt.setFloat(index, value);
}
/**
* @function setBytes
* @param index
* int
* @param value
* byte[]
* @throws SQLException
*/
public void setBytes(int index, byte[] value) throws SQLException {
prepstmt.setBytes(index, value);
}
/**
* @function setBinaryStream
* @param index
* int
* @param value
* InputStream
* @param len
* int
* @throws SQLException
*/
public void setBinaryStream(int index, InputStream value, int len)
throws SQLException {
prepstmt.setBinaryStream(index, value, len);
}
/**
* @function setTimestamp
* @param index
* int
* @param timestamp
* Timestamp
* @throws SQLException
*/
public void setTimestamp(int index, Timestamp timestamp)
throws SQLException {
prepstmt.setTimestamp(index, timestamp);
}
/**
* @function setAutoCommit
* @param value
* boolean
* @throws SQLException
*/
public void setAutoCommit(boolean value) throws SQLException {
if (conn != null)
conn.setAutoCommit(value);
}
/**
* @function commit
* @throws SQLException
*/
public void commit() throws SQLException {
conn.commit();
}
/**
* @function rollback
* @throws SQLException
*/
public void rollback() throws SQLException {
conn.rollback();
}
/**
* @function close
* @throws Exception
*/
public void close() {
try {
if (rs != null) {
rs.close();
rs = null;
}
} catch (Exception e) {
System.out.println("OradbUtil close rs error!");
} finally {
try {
if (stmt != null) {
stmt.close();
stmt = null;
}
} catch (Exception e) {
System.out.println("OradbUtil close stmt error!");
} finally {
try {
if (prepstmt != null) {
prepstmt.close();
prepstmt = null;
}
} catch (Exception e) {
System.out.println("OradbUtil close prepstmt error!");
} finally {
try {
if (conn != null) {
conn.close();
conn = null;
}
} catch (Exception e) {
System.out.println("OradbUtil close conn error!");
}
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -