lz给你个参考吧
package org.lxy.demo.jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class DataBaseConnection {
private static final String DBDRIVER="org.gjt.mm.mysql.Driver";
private static final String DBURL="jdbc:mysql://localhost:3306/user";
private static final String DBUSER="root";
private static final String DBPASS="mysqladmin";
private Connection con=null;
public DataBaseConnection(){
try {
Class.forName(DBDRIVER);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
try {
con=DriverManager.getConnection(DBURL,DBUSER,DBPASS);
} catch (SQLException e) {
e.printStackTrace();
}
}
public Connection getConnection(){
return this.con;
}
public void close(){
if(con!=null){
try {
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
URL (数据库连接字)要写对
Driver 要写对
用户,口令也要对
开启sqlserver服务了吗
com.microsoft.sqlserver.jdbc.SQLServerDriver
这个是SQL2005的驱动名字
看服务里,看下SQL SERVER的实例是不是开启的,开启的哪个实例?