這兒有一個資料連線,大家看這兒有哪些問題
package tools;
import javax.naming.*;
import javax.sql.*;
import java.sql.*;
import oracle.jdbc.pool.*;
public class Conn{
private Connection conn = null;
private Statement st = null;
private Statement st2 = null;
private ResultSet rs = null;
private PreparedStatement pst = null;
public Conn() throws Exception{
//'查詢連線池並連線
OracleDataSource ods = new OracleDataSource();
ods.setURL("jdbc:oracle:thin:@192.168.0.1:1521:oracle");
ods.setUser("username");
ods.setPassword("password");
conn = ods.getConnection();
}
public void close() throws Exception{
if(st != null){
st.close();
st = null;
}
if(pst != null){
st.close();
st = null;
}
conn.close();
}
public void createStatement() throws Exception{
st = conn.createStatement();
}
public void createStatement2() throws Exception{
st2 = conn.createStatement();
}
public void createStatementB() throws Exception{
st = conn.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_READ_ONLY);
}
public void setAutoCommit(boolean bl) throws Exception{
conn.setAutoCommit(bl);
}
public Connection getConnection() throws Exception{
return conn;
}
public void execute(String sql) throws Exception{
setAutoCommit(true);
pst = conn.prepareStatement(sql);
pst.executeUpdate();
conn.commit();
pst.close();
pst = null;
}
public ResultSet executeQuery(String s) throws Exception {
createStatement();
rs = st.executeQuery(s);
return rs;
}
public ResultSet executeQuery() throws Exception {
rs = pst.executeQuery();
return rs;
}
public ResultSet executeQueryB(String s) throws Exception {
createStatementB();
rs = st.executeQuery(s);
return rs;
}
public void insert(String s) throws Exception {
setAutoCommit(true);
pst = conn.prepareStatement(s);
}
public void executeInsert() throws SQLException {
pst.executeUpdate();
}
public void executeUpdate(String s) throws Exception {
setAutoCommit(true);
st = conn.createStatement();
st.executeUpdate(s);
}
public int getCount(String table,String condition) throws Exception{
String _condition = "";
int RowCount;
if(condition.length() != 0)
_condition = " where "+condition;
createStatement();
String sql = "select count(*) as RC from "+table+_condition;
rs = st.executeQuery(sql);
rs.next();
RowCount = rs.getInt("RC");
return RowCount;
}
public String[][] SelectData(
String Table,
String[] Column,
String[] Column_Attr,
String Condition,
String Order) throws Exception{
createStatement();
//求出個數
int count = getCount(Table,Condition);
String[][] Results = new String[count][Column.length];
String _Column = "";
for(int i = 0; i < Column.length; i++)
{
_Column+=Column+",";
}
_Column = _Column.substring(0,_Column.length()-1);
String _Condition = "";
if(Condition.length() != 0)
_Condition = " where "+Condition;
String sql = "select "+_Column+" from "+Table+_Condition+" "+Order;
rs = st.executeQuery(sql);
int m=0;
while(rs.next()) {
for(int i = 0; i < Column.length; i++){
if(Column_Attr.equalsIgnoreCase("String"))
Results[m] = rs.getString(Column);
else if(Column_Attr.equalsIgnoreCase("Int"))
Results[m] = String.valueOf(rs.getInt(Column));
else if(Column_Attr.equalsIgnoreCase("Date"))
if(rs.getDate(Column) != null)
Results[m] = rs.getDate(Column).toString();
else
Results[m] = "";
else if (Column_Attr.equalsIgnoreCase("Time"))
if(rs.getDate(Column) != null)
Results[m] = rs.getDate(Column).toString()+" "+rs.getTime(Column).toString();
else
Results[m] = "";
}
m++;
}
return Results;
}
public void setString(int i,String s) throws SQLException {
pst.setString(i, s);
}
public void setInt(int i, int j) throws SQLException{
pst.setInt(i,j);
}
public void setFloat(int i,float f) throws SQLException{
pst.setFloat(i,f);
}
public void setDouble(int i ,double d) throws SQLException{
pst.setDouble(i,d);
}
public void setLong(int i,long l) throws SQLException {
pst.setLong(i,l);
}
public void setDate(int i ,Date d) throws SQLException {
pst.setDate(i,d);
}
public void setBoolean(int i,boolean b) throws SQLException{
pst.setBoolean(i,b);
}
public void setTimestamp(int i,Timestamp t) throws SQLException{
pst.setTimestamp(i,t);
}
}
1。在執行關閉操作時,特別是執行insert操作時會有異常!
2。這個程式在寫法上有哪些不足,在思想上應有哪些值得改進!
3、用這個執行查詢操作時,資料庫有近10萬記錄時很慢,並透過常有記憶體不足的提示。如果查詢人數多的時候給導致伺服器崩掉!
請教各位高手賜教!我在這兒先謝了!
相關文章
- 這兒有20道大廠面試題等你查收面試題
- 當Synchronized遇到這玩意兒,有個大坑,要注意!synchronized
- 這兒有一個使你網頁效能提升10倍的工具網頁
- 有關webscraper的問題,看這個就夠了Web
- WinJS 開源和 TypeScript?這事兒有模板JSTypeScript
- 在這兒下的 jdon有沒有在sybase資料庫下執行成功的朋友?資料庫
- 大家看我這段程式碼有什麼問題麼?
- 資料庫安全問題?這裡有10個最常見的資料庫
- 這個安全系統讓無人機巡邏 超安全還倍兒有面子無人機
- 請大家幫我分析一下這個畢業設計題目是不是有問題?
- 這個jndi連線資料來源的問題怎麼解決?
- 圖靈社群線下沙龍——Linux就是這個範兒圖靈Linux
- 這一年我有了妻兒卻落了技術 | 掘金年度徵文
- 大資料資訊保安問題有哪些大資料
- 就是這個味兒~15款復古範兒十足的WordPress主題推薦
- 有關指標的那些事兒《一》指標
- 問一個有關JBPM連MySQL資料庫的問題,高手請進MySql資料庫
- 資料庫連線池的問題,連線池物件為靜態變數有問題麼資料庫物件變數
- 好用的Mac筆記軟體有哪些?看這裡Mac筆記
- 大家看看這個問題能否解決?關於無線應用
- 一個資料庫連線池的問題資料庫
- 就要這個範兒——娶妻當娶LinuxLinux
- 試讀《Linux就是這個範兒》有感Linux
- 《Linux就是這個範兒》試讀有感Linux
- 試讀《Linux 就是這個範兒》 有感Linux
- 聊聊GOOGLE說要退出中國這個事兒Go
- 一個爬蟲的故事:這是人乾的事兒?爬蟲
- 資料庫連線沒有釋放造成的奇怪問題資料庫
- 如何讀取 JSON 裡巢狀的深層資料?我這兒有各語言通用方案JSON巢狀
- Java有哪些從業方向?分享這9個Java
- APP註冊這點事兒APP
- 遊戲想自個兒恰飯有多難?遊戲
- 租房注意事項,有哪些你不懂,程式猿看這裡……
- 一個資料庫連線問題!請教高手資料庫
- Spring Boot 第六彈,攔截器如何配置,看這兒~Spring Boot
- 你有哪些寫了Flutter 之後才知道的事兒Flutter
- 看過來,這裡有一份企業資料完整遷移策略
- 真格基金:資料談初創公司品牌建設這件事兒