动态链接jdbc
来源:互联网 发布:网络创新设计大赛作品 编辑:程序博客网 时间:2024/05/16 06:33
String connectionUrl = "jdbc:sqlserver://192.168.0.247:1433;"
+ "databaseName=northwind;";
// Declare the JDBC objects.
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
try {
Properties pro = new Properties();
pro.setProperty("user", "sa");//设置用户名
pro.setProperty("password", "sa");//设置密码
File file = new File(
"C://Program Files//Microsoft SQL Server JDBC Driver 3.0//sqljdbc_3.0//chs//sqljdbc.jar");
URL url = file.toURL();
URLClassLoader loader = new URLClassLoader(new URL[] { url },
ClassLoader.getSystemClassLoader());
java.sql.Driver driver = (java.sql.Driver) loader.loadClass(
"com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
driver.connect(connectionUrl, pro);//需要使用java.sql.Driver.connect链接
JOptionPane.showMessageDialog(null, "数据库连接成功!");
}
catch (Exception e) {
e.printStackTrace();
}
finally {
if (rs != null)
try {
rs.close();
} catch (Exception e) {
}
if (stmt != null)
try {
stmt.close();
} catch (Exception e) {
}
if (con != null)
try {
con.close();
} catch (Exception e) {
}
}
}
- 动态链接jdbc
- jdbc链接
- JDBC链接
- JDBC 链接
- java ODBC链接 JDBC链接
- 动态链接
- 动态链接
- 动态链接
- 动态链接
- 动态链接
- 动态链接
- 动态链接
- 动态链接
- 动态链接
- 动态链接
- 动态链接
- 动态链接
- 动态链接
- C#使用Firebird嵌入版数据库
- 用debug对DELL笔记本电脑硬盘低格
- c#值传递和引用传递,以及ref和out关键字的区别
- 理发店模型与性能测试
- C#使用Firebird嵌入版数据库
- 动态链接jdbc
- DirectorySearcher 的PropertiesToLoad所有属性
- Linux输入输出重定向以及管道
- 嵌入式C语言中的volatile关键字
- ASP.NET状态管理之四:Cache
- IE7中onpropertychange引发的Stack overflow at line xxx问题解决
- 精彩 PuTTY 中文教程
- 开始了
- Linux的单用户、修复模式等在系统修复中的运用