package fxb.grp.utils;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import fxb.grp.model.OracleTest;
/**
* 获取数据量连接
* @author DREAM
*
*/
public class GetConnectUtils {
/**
* 构造方法
* @param sql
* @param opType 操作类型 0查询 1非查询
*/
public GetConnectUtils(String sql) {
System.out.println("进入构造方法!");
}
//初始化方法
public static List<OracleTest> init(String sql) {
List<OracleTest> listMap = new ArrayList<OracleTest>();
Connection conn = null;
Statement st = null;
ResultSet rs = null;
String driver;
String url;
String user;
String pwd;
driver = "oracle.jdbc.driver.OracleDriver";
url = "jdbc:oracle:thin:@127.0.0.1:1521/orcl";
user = "salary";
pwd = "a";
try {
Class.forName(driver);
conn = DriverManager.getConnection(url, user, pwd);
st = conn.createStatement();
if(sql.contains("select")) {
System.out.println("进入查询方法!");
rs = st.executeQuery(sql);
while(rs.next()) {
OracleTest ot = new OracleTest();
ot.setId(rs.getLong(1));
ot.setCode(rs.getString(2));
ot.setName(rs.getString(3));
ot.setCreate_datetime(rs.getTimestamp(4));
ot.setLast_op_datetime(rs.getTimestamp(5));
ot.setLast_ver(rs.getLong(6));
ot.setIs_deleted(rs.getInt(7));
listMap.add(ot);
}
}else{
System.out.println("进入增删改方法!");
st.execute(sql);
}
} catch (Exception e) {
e.printStackTrace();
}finally {
System.out.println("数据库操作结束!");
}
return listMap;
}
}
oracle数据库连接
最新推荐文章于 2024-11-11 23:47:19 发布