我们如何给jdbc连接? [英] how we can give jdbc connection?
本文介绍了我们如何给jdbc连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
PLZ建议一个链接,它将提供一个jdbc连接?
plz suggest a link which will give a jdbc connection?
推荐答案
看看这些:
JDBC连接 [ ^ ]
教程:JDBC - 数据库连接 [ ^ ]
用Java连接到MySQL数据库 [ ^ ]
如果需要,请查看此处 [ ^ ]了解更多。
Have a look at these:
JDBC connection[^]
Tutorial: JDBC - Database Connections[^]
Connecting to a MySQL Database in Java[^]
If needed, look here[^] for more.
package apptest;
import java.sql.*;
public class AppTest {
// Code s7 Worked
public static void main(String[] args) {
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String connectionUrl = "jdbc:sqlserver://localhost:1433;"
+ "databaseName=Northwind;user=sa;password=;";
Connection con = DriverManager.getConnection(connectionUrl);
Statement stmt = null;
ResultSet rs = null;
// SQL query command
String SQL = "SELECT * FROM Products";
stmt = con.createStatement();
System.out.println("Connection is created...");
rs = stmt.executeQuery(SQL);
while (rs.next()) {
System.out.println(rs.getString("ProductName") + " : " + rs.getString("UnitPrice"));
System.out.println(" done");
}
con.close();
System.out.println("Connection is closed...");
} catch (SQLException e) {
System.out.println("SQL Exception: " + e.toString());
} catch (ClassNotFoundException cE) {
System.out.println("Class Not Found Exception: " + cE.toString());
}
}
}
这篇关于我们如何给jdbc连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文