java web 与sql 2008相连接做个项目但知道java web连接数据库的语句该如何写?

2024-12-22 10:35:04
推荐回答(3个)
回答1:

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

回答2:

搜JDBC连接数据库 有详细解答!

回答3:

http://www.blogjava.net/QJames/archive/2010/12/09/340181.html

这个讲的