//获取数据库连接(原生)
public class ConnectionHelper { private static ConnectionHelper instance = null; synchronized public static ConnectionHelper getInstance(){ if(null == instance){ instance = new ConnectionHelper(); } return instance; } public Connection getDbConn(){ //从配置文件获取配置的数据库地址,名称,密码 String dbUrl = ConfigProperties.getProperty("dbUrl"); String dbName = ConfigProperties.getProperty("dbName"); String dbPass = ConfigProperties.getProperty("dbPass"); Connection dbConn = com.jshx.helper.JdbcHelper.getJdbcConn(dbUrl, dbName, dbPass); return dbConn; } }
//其它类中获取数据库连接调用方法
Connection dbConn = ConnectionHelper.getInstance().getDbConn();
//调用sql语句进行查询操作(查询到返回true,否则返回false)
public static boolean searchDataSql(Connection conn, String parameter) throws Exception { boolean flag = false; PreparedStatement ps = conn.prepareStatement("SELECT * FROM student WHERE id = ? "); ps.setString(1, parameter); ResultSet rs = ps.executeQuery(); if (rs.next()) { flag = true; } ps.close(); return flag; }
//调用sql语句删除指定数据
String delSql="DELETE FROM student where id='12312'"
//数据导出数据中带换行符写入文本文件导致一个字段分了好几行的解决办法
replace(replace(address,chr(13),''),chr(10),'') AS address,
//数据库字段类型为BINARY_DOUBLE导出数据值过长问题解决
CAST(studentArea as NUMBER(18,0)) studentArea , //整数====这个18根据自己的业务字段长度来定义
CAST(studentArea as NUMBER(18,4)) studentArea , //带小数=====这个4根据自己的业务字段小数部分来定义