java怎麼讀init文件 rt 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我觉得你可以自己写一个去读取, 结果放到一个properties里面。一行一行的读。遇到[]做一些特殊处理。 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;}} 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;}} 关于java接口的一点疑问 程序探讨 JDBC例子? Java初级问题:学习Java需要准备什么 关于Graphics的问题 applet从后台下载数据的问题? 请问各位鼠标右键时间怎么写????在线等,解决马上加分 关于正则表达式的问题,会者请进,up有分。 如何优化?这四个问题怎么解决? jdbc,不懂,一定给分! JAVA 如何用程序生成数据库 实例和表结构 java调用shell返回值问题
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;
}
}
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;
}
}