|
|
|
@ -2,6 +2,7 @@ package dao;
|
|
|
|
|
|
|
|
|
|
import java.sql.*;
|
|
|
|
|
|
|
|
|
|
import error.GExcptSQL;
|
|
|
|
|
import org.apache.tomcat.jdbc.pool.DataSource;
|
|
|
|
|
import org.apache.tomcat.jdbc.pool.PoolProperties;
|
|
|
|
|
|
|
|
|
@ -41,7 +42,7 @@ public class DBManagement {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static ResultSet query(String sql) {
|
|
|
|
|
public static ResultSet query(String sql) throws Exception {
|
|
|
|
|
if(!ifInit) return null;
|
|
|
|
|
ResultSet rs = null;
|
|
|
|
|
Connection con = null;
|
|
|
|
@ -50,19 +51,19 @@ public class DBManagement {
|
|
|
|
|
Statement stmt = con.createStatement();
|
|
|
|
|
rs = stmt.executeQuery(sql);
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
throw new GExcptSQL("Connect Failure");
|
|
|
|
|
}finally {
|
|
|
|
|
if(con!=null) {
|
|
|
|
|
try {
|
|
|
|
|
con.close();
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
throw new GExcptSQL("Connection Close Failure");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return rs;
|
|
|
|
|
}
|
|
|
|
|
public static void update(String sql) {
|
|
|
|
|
public static void update(String sql) throws GExcptSQL {
|
|
|
|
|
if(!ifInit) return;
|
|
|
|
|
Connection con = null;
|
|
|
|
|
try{
|
|
|
|
@ -70,14 +71,14 @@ public class DBManagement {
|
|
|
|
|
Statement stmt = con.createStatement();
|
|
|
|
|
stmt.executeUpdate(sql);
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
throw new GExcptSQL("Connect Failure");
|
|
|
|
|
}finally {
|
|
|
|
|
if(con!=null) {
|
|
|
|
|
try {
|
|
|
|
|
con.close();
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
throw new GExcptSQL("Connection Close Failure");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|