JinghuaConn.java
资源名称:0102010.rar [点击查看]
上传用户:nbluoke
上传日期:2013-08-09
资源大小:4851k
文件大小:5k
源码类别:
教育系统应用
开发平台:
WORD
- package jinghua;
- /**
- * <p>Title: Jinghua-TestOnline</p>
- * <p>Description: </p>
- * <p>Copyright: Copyright (c) 2003</p>
- * <p>Company: Bit</p>
- * @author ChengBaodong
- * @version 1.0
- */
- import java.sql.*;
- //sqlConn=java.sql.DriverManager.getConnection(
- //"jdbc:mysql://localhost/train?user=support&password=support&useUnicode=true&characterEncoding=gb2312");
- //String MM_con1_DRIVER = "com.mysql.jdbc.Driver";
- //String MM_con1_USERNAME = "root";
- //String MM_con1_PASSWORD = "";
- //String MM_con1_STRING = "jdbc:mysql://localhost/jinghua";
- //Driver DriverRecordset1 = (Driver)Class.forName(MM_con1_DRIVER).newInstance();
- //Connection Con = java.sql.DriverManager.getConnection(MM_con1_STRING,MM_con1_USERNAME,MM_con1_PASSWORD);
- public class JinghuaConn {
- private static String rootpath="D:\JavaApp\Jinghua\test_online";
- private static String chartPath="D:\JavaApp\Jinghua\test_online\chart\temp";
- // private static String rootpath="/sfroot/home/groups/jsptestonline";
- // private static String chartPath="/sfroot/home/groups/jsptestonline/chart/temp";
- private String sample = "Sample";
- private Connection con = null;
- private Statement stmt = null;
- ResultSet rs = null;
- private static final String DRIVER = "com.mysql.jdbc.Driver";
- private static final String USERNAME = "root";
- private static final String PASSWORD = "";
- private static final String HOST = "http://localhost:8080";
- // private static final String HOST = "http://jsptestonline.cosoft.org.cn";
- private static final String PHYPATH = "D:/JavaApp/Jinghua/test_online";
- // private static final String PHYPATH = "/sfroot/home/groups/jsptestonline";
- private static final String CONNECTION_STRING =
- "jdbc:mysql://localhost/jinghua";
- public static String getRootPath(){
- return rootpath;
- }
- public static String getChartPath(){
- return chartPath;
- }
- public JinghuaConn() {
- try {
- Driver DriverJinghua = (Driver) Class.forName(DRIVER).newInstance();
- //Con = DriverManager.getConnection(CONNECTION_STRING,USERNAME,PASSWORD);
- }
- catch (ClassNotFoundException e) {
- System.err.println("JinghuaConn():" + e.toString());
- }
- catch (Exception e) {
- System.err.println("JinghuaConn():" + e.toString());
- }
- }
- public Connection getConnection() {
- try {
- //Con = DriverManager.getConnection(CONNECTION_STRING,USERNAME,PASSWORD);
- String strUrl = CONNECTION_STRING + "?user=" + USERNAME +
- "&password=" +
- PASSWORD + "&useUnicode=true&characterEncoding=gb2312";
- con = DriverManager.getConnection(strUrl);
- }
- catch (Exception e) {
- con = null;
- }
- return con;
- }
- public void dropConnection() {
- try {
- closeStmt();
- con.close();
- }
- catch (Exception ignored) {}
- finally {
- con = null;
- }
- }
- public ResultSet executeQuery(String sql) {
- rs = null;
- try {
- //conStr = conStr + user ;
- con = getConnection();
- stmt = con.createStatement();
- rs = stmt.executeQuery(sql);
- }
- catch (SQLException ex) {
- System.err.println("JinghuaConn.executeQuery(): " + ex.getMessage() );
- }
- return rs;
- }
- public void executeUpdate(String sql) {
- stmt = null;
- rs = null;
- try {
- //conStr = conStr + user ;
- con =getConnection();
- stmt = con.createStatement();
- stmt.executeUpdate(sql);
- stmt.close();
- con.close();
- }
- catch (SQLException ex) {
- System.err.println("JinghuaConn:executeUpdate(): " + ex.getMessage());
- }
- }
- public void execute(String sql) {
- stmt = null;
- rs = null;
- try {
- //conStr = conStr + user ;
- con = getConnection();
- stmt = con.createStatement();
- stmt.execute(sql);
- stmt.close();
- con.close();
- }
- catch (SQLException ex) {
- System.err.println("JinghuaConn:execute(): " + ex.getMessage());
- }
- }
- public void closeStmt() {
- try {
- stmt.close();
- }
- catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public void closeConn() {
- try {
- con.close();
- }
- catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }