用JDBC连接sql 2005出现的问题???

来源:百度知道 编辑:UC知道 时间:2024/05/27 06:50:53
import java.sql.*;
class sql2005Demo
{
public static void main(String args[])
{
String classdriver="com.microsoft.sqlserver.jdbc.SQLServerDriver";
try{
Class.forName(classdriver).newInstance();
}catch(ClassNotFoundException e){
throw new UnavailableException("连接数据库失败");
}
String url="jdbc:sqlserver://localhost:1433;DatabaseName=LearnJSP";
/*
我登陆时用的是windows默认模式,下面是我在用户管理改的sa密码
*/
String user="sa";
String password="baixuer519103";//sa的密码
Connection con=null;
Statement stmt=null;
ResultSet rs=null;
try{
con=DriverManager.getConnection(url,user,password);
stmt=con.createStatement();
rs=stmt.executeQuery("select * from dbo.UserInfo");
while(rs.next())
{

2000需要打补丁才能使用jdbc连接,但2005应该不需要了
计算机名发生更改也会可能导致查询分析器连不上
另外安装时在“域”选项做了设置,连接也会出现一些麻烦

建议重装sql2005