rt

解决方案 »

  1.   

     我觉得你可以自己写一个去读取, 结果放到一个properties里面。一行一行的读。遇到[]做一些特殊处理。
      

  2.   

    package com.ssnh.db;
    import com.mysql.jdbc.*;
    import java.io.*;
    import java.sql.*;
    import java.util.Properties;import javax.servlet.ServletContext;
    import javax.servlet.jsp.PageContext;
    public class DBConnection {
    private String userName = "";
    private String password = "";
    private String dataName = "";
    private String serviceUrl = "";
    private ServletContext pc = null;
    //private LinkedHashMap hm = null;
    private java.sql.Connection conn = null;public void init(ServletContext pc)
    {
    this.pc = pc;
    }
    public Exception connectionDB()
    {
    Exception ex = null;
    if(this.conn!=null)
    {
    return ex;
    }
    if(!this.getConfigPara())
    {
    return new Exception("读取配置文件出错!");
    }String url = "jdbc:mysql://"+serviceUrl+"/"+dataName+"?user="+userName+"&password="+password;
    try {
    DriverManager.registerDriver(new com.mysql.jdbc.Driver());
    this.conn = DriverManager.getConnection(url);
    System.out.println("begin a connection");
    } catch (Exception e) {
    ex = e;
    }
    return ex;
    }public java.sql.Connection getConn() {
    return conn;
    }
    public boolean closeConn()
    {
    if(this.conn!=null)
    {
    try 
    {
    this.conn.close();
    System.out.println("end a connection");
    return true;

    catch (SQLException e) 
    {e.printStackTrace();
    return false;
    }
    }
    return true;
    }
    private boolean getConfigPara()
    {
    if(this.pc==null)
    {
    return false;
    }
    try {
    String fpath = pc.getRealPath("/")+"/conf/config.ini";
    FileInputStream fis = new FileInputStream(fpath);
    Properties pp = new Properties();
    pp.load(fis);
    this.serviceUrl = pp.get("serviceUrl").toString();
    this.dataName = pp.get("dataName").toString();
    this.userName = pp.get("username").toString();
    this.password = pp.get("password").toString();
    } catch (Exception e) {
    e.printStackTrace();
    return false;
    }
    return true;
    }
    }
      

  3.   

    package com.ssnh.db;
    import com.mysql.jdbc.*;
    import java.io.*;
    import java.sql.*;
    import java.util.Properties;import javax.servlet.ServletContext;
    import javax.servlet.jsp.PageContext;
    public class DBConnection {
    private String userName = "";
    private String password = "";
    private String dataName = "";
    private String serviceUrl = "";
    private ServletContext pc = null;
    //private LinkedHashMap hm = null;
    private java.sql.Connection conn = null;public void init(ServletContext pc)
    {
    this.pc = pc;
    }
    public Exception connectionDB()
    {
    Exception ex = null;
    if(this.conn!=null)
    {
    return ex;
    }
    if(!this.getConfigPara())
    {
    return new Exception("读取配置文件出错!");
    }String url = "jdbc:mysql://"+serviceUrl+"/"+dataName+"?user="+userName+"&password="+password;
    try {
    DriverManager.registerDriver(new com.mysql.jdbc.Driver());
    this.conn = DriverManager.getConnection(url);
    System.out.println("begin a connection");
    } catch (Exception e) {
    ex = e;
    }
    return ex;
    }public java.sql.Connection getConn() {
    return conn;
    }
    public boolean closeConn()
    {
    if(this.conn!=null)
    {
    try 
    {
    this.conn.close();
    System.out.println("end a connection");
    return true;

    catch (SQLException e) 
    {e.printStackTrace();
    return false;
    }
    }
    return true;
    }
    private boolean getConfigPara()
    {
    if(this.pc==null)
    {
    return false;
    }
    try {
    String fpath = pc.getRealPath("/")+"/conf/config.ini";
    FileInputStream fis = new FileInputStream(fpath);
    Properties pp = new Properties();
    pp.load(fis);
    this.serviceUrl = pp.get("serviceUrl").toString();
    this.dataName = pp.get("dataName").toString();
    this.userName = pp.get("username").toString();
    this.password = pp.get("password").toString();
    } catch (Exception e) {
    e.printStackTrace();
    return false;
    }
    return true;
    }
    }