properties是资源文件
和ResourceBundle类直接有直接关系
你应该且必须看看这个类的API文件格式
key = value
此文件是locale相关的native2ascii 1.properties 1_zh_CN.properties
和ResourceBundle类直接有直接关系
你应该且必须看看这个类的API文件格式
key = value
此文件是locale相关的native2ascii 1.properties 1_zh_CN.properties
调试欢乐多
DBName DBDriver DBURL DBUser DBPassword
中间用空隔隔开
例如:URL=HTTP://LOACAST:8080/TEST/SERVLET.CLASS之类
URI=/servlet/MasterServlet
仅供参考
我只是想写一个连接池的db.properties文件
就叫这个名字
以DB2为例:
database.driver=COM.ibm.db2.jdbc.app.DB2Driver
database.url=jdbc:db2:test
database.user=db2admin
database.password=db2admin
database.maxConnections=50
database.initConnections=2
言者有分!!!
logfile=C:\\log.txt
driver=sun.jdbc.odbc.JdbcOdbcDriver
myconn.url=jdbc:odbc:nettest
myconn.user=sa
myconn.maxConnections=50
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class TestServlet extends HttpServlet {
private DBConnectionManager connMgr;
public void init(ServletConfig conf) throws ServletException {
super.init(conf);
connMgr = DBConnectionManager.getInstance();
}
public void service(HttpServletRequest req, HttpServletResponse res)
throws IOException {
res.setContentType("text/html");
PrintWriter out = res.getWriter();
Connection con = connMgr.getConnection("myconn");
if (con == null) {
out.println("不能获取数据库连接.");
return;
}
ResultSet rs = null;
ResultSetMetaData md = null;
Statement stmt = null;
try {
stmt = con.createStatement();
rs = stmt.executeQuery("SELECT * FROM test");
md = rs.getMetaData();
out.println("< H1>职工数据< /H1>");
while (rs.next()) {
out.println("< BR>");
for (int i = 1; i < md.getColumnCount(); i++) {
out.print(rs.getString(i) + ", ");
}
}
stmt.close();
rs.close();
}
catch (SQLException e) {
e.printStackTrace(out);
}
connMgr.freeConnection("myconn", con);
}
public void destroy() {
connMgr.release();
super.destroy();
}
}
servlet.password = testweb
servlet.source = jdbc:odbc:nettest
servlet.host = 192.168.3.210
servlet.port = 1521
servlet.sid = sfhc private static final String DATABASE_DRIVER="sun.jdbc.odbc.JdbcOdbcDriver"; private static final String DATABASE_URL="jdbc:odbc:nettest";// 数据库连接名
//或者从properties中获得 Class.forName(DATABASE_DRIVER).newInstance(); try {
conn=DriverManager.getConnection(DATABASE_URL);//链接数据库
} catch (Exception e) {
System.out.println("ERROR "+ e.toString());
};
// 取得 Properties 文件中定义的参数的值。
try {
PropertyResourceBundle configBundle = (PropertyResourceBundle)PropertyResourceBundle.getBundle(CONFIG_BUNDLE_NAME);
user = configBundle.getString("servlet.user");
password = configBundle.getString("servlet.password");
source = configBundle.getString("servlet.source");
host = configBundle.getString("servlet.host");
port = configBundle.getString("servlet.port");
sid = configBundle.getString("servlet.sid");
url = source + host + ":" + port + ":" +sid;
} catch (Exception e) {
System.out.println("Find properties error in index.init(): " + e.toString());
}
[email protected]
分要多少有多少