最近公司在做一个项目是关于一个省的大数据同计类的数据可视化系统,系统操作单表百万级的数据查改操作,前期使用公司的基础框架会产生内存溢出,因为导出的库不支持分页处理,所以就相当与数据的一次性导入。在缺少可用的框架的情况下尝试了无数次才发现还是手写的JDBC最好用,但好久没用了,不会封装了,今天写这个作为本人总结吧!!
DBdriver=oracle.jdbc.driver.OracleDriver
DBconnstr=jdbc:oracle:thin:@localhost:1521:orcl
DBuser=LYSJCK
DBpwd=123456
读取方法
public String getXMLPath(){
String rslt = null;
try {
rslt = this.getClass().getResource("").toURI().getPath().substring(1);
} catch (URISyntaxException e) {
e.printStackTrace();
rslt = this.getClass().getResource("").getPath().substring(1).replaceAll("%20", " ");
}
rslt = rslt.substring(0,rslt.replace('\\','/').indexOf("×××××××"));
return rslt;
}
//获取WEB-INF下的文件配置路径
private String getCofig(){
String xmlPath = confReader.getXMLPath();
String path=xmlPath+"config/TongDaHaiDBConfig.properties";
return path;
}
//将上面方法获取到的路径放入本方法处理得到文件 再讲
文件处理放入Properties
public static Properties getProper(String path) throws Exception{
File file=new File(path);
FileReader fileReader = new FileReader(file);
BufferedReader bufferedReader = new BufferedReader(fileReader);
Properties pro = new Properties();
pro.load(bufferedReader);
return pro;
}
//将获取到的 propretitesfa放入方法中的到链接
public Connection getCon(String path){
String getPath = this.GetPath()+path;
Properties pro = this.getProperties(getPath);
Connection connection=null;
try {
getClass().forName(String.valueOf(pro.getProperty("DBdriver")));
connection = DriverManager.getConnection(String.valueOf(pro.get("DBconnstr")), String.valueOf(pro.get("DBuser")), String.valueOf(pro.get("DBpwd")));
} catch (Exception e) {
e.printStackTrace();
}
return connection;
}
//接下来是对操作数据库的简单封装
package com.liyu;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class LiYuQueary {
private Connection con=null;
private static LiYuQueary instance=null;
//构造函数
public LiYuQueary(){
Connection con = getCon("config/Orcal.properties");
}
//单例模式
public static LiYuQueary newInstance(){
if(instance==null)instance = new LiYuQueary();
return instance;
}
//获取链接
public static Connection getCon(String path){
LiYuJDBC liYuJDBC = new LiYuJDBC();
return liYuJDBC.getCon(path);
}
//返回List类型的查询结果
public List