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;
}}
解决方案 »
- jdk1.5 or 1.6
- 通用的数据库访问问题?
- Swing的思考 请大家进来看看啊
- java技术交流群:12375387,欢迎大家来一起研讨,一起进步~~~
- Java居然不能取得文件创建日期 ?只有一个lastModified()是最后修改日期呀。
- ◎◎◎昨儿晚上和他打招呼,被冷冰冰的拒绝了,求救◎◎◎
- *****弟兄们,遇到难题了,用eclipse用其内置的cvs通过代理服务器登录国外的cvs服务器的问题,
- 关于JBuilder的问题,谢谢 !!!
- 初学者 的 问题
- 怎样编写动画程序?
- 如果一个类的特定元素(如方法)为静态方法(static),那么方法调用其它方法时,其它的方法是不是一定要为静态访求(static)?
- 我应该用synchronized关键字吗????谢谢!!!!
http://www.microsoft.com/china/sql/downloads/2000/jdbc.asp