package database;import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;/**
* @author jerrychen
*
* To change this generated comment edit the template variable "typecomment":
* Window>Preferences>Java>Templates.
* To enable and disable the creation of type comments go to
* Window>Preferences>Java>Code Generation.
*/
public class DBConnect {
public DBConnect(){
}
public static Connection getConnect() throws SQLException{
//String url = "jdbc:odbc:school";
String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=school;User=sa;Password=sa";
Connection con = null;
try {
//Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
con = DriverManager.getConnection(url);
} catch (ClassNotFoundException e) {
System.err.println(e.getMessage());
}
if(con == null){
throw new SQLException("didn't get connection!");
}
return con;
}}
import java.sql.DriverManager;
import java.sql.SQLException;/**
* @author jerrychen
*
* To change this generated comment edit the template variable "typecomment":
* Window>Preferences>Java>Templates.
* To enable and disable the creation of type comments go to
* Window>Preferences>Java>Code Generation.
*/
public class DBConnect {
public DBConnect(){
}
public static Connection getConnect() throws SQLException{
//String url = "jdbc:odbc:school";
String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=school;User=sa;Password=sa";
Connection con = null;
try {
//Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
con = DriverManager.getConnection(url);
} catch (ClassNotFoundException e) {
System.err.println(e.getMessage());
}
if(con == null){
throw new SQLException("didn't get connection!");
}
return con;
}}
解决方案 »
- xmpp协议
- 为什么在任务管理器中看到有程序没有响应,但tasklist命令却查看不到?
- 怎么在jlabel 上点下就到指定的一个网址 ??
- 关于main中FileInputStream的引用的赋初值问题
- 如何修改Swing默认风格?
- 一年又过去了,感觉自己一事无成,唉!忘掉过去!2004奋发向前!
- 什么时候定义静态类
- 一个五子棋程序的错误
- simple question
- 请问,如何实现并处理JTree节点Multi-Selected?
- 如果一个类的特定元素(如方法)为静态方法(static),那么方法调用其它方法时,其它的方法是不是一定要为静态访求(static)?
- 我应该用synchronized关键字吗????谢谢!!!!
http://www.microsoft.com/china/sql/downloads/2000/jdbc.asp