java 文件
//取得数据库连接资源文件
private static Properties getProp() throws Exception {
Properties p = new Properties();
FileInputStream is = null;
try {
is = new FileInputStream(".\\conf\\connect.prop");
p.load(is);
} finally {
if (is != null)
is.close();
}
return p;
}
//取得源数据库连接
private static Connection getConnection1(Properties p) throws Exception {
String sURL = (String) p.get("db1.URL");
String sUser = (String) p.get("db1.user");
String sPasswd = (String) p.get("db1.password");
Class.forName("net.sourceforge.jtds.jdbc.Driver"); return DriverManager.getConnection(sURL, sUser, sPasswd);
}
conf.properties:
#源数据库连接
db1.URL=jdbc:jtds:sqlserver://127.0.0.1:1433/stu
db1.user=sa
db1.password=123
搜JDBC连接数据库 有详细解答!
http://www.blogjava.net/QJames/archive/2010/12/09/340181.html
这个讲的