sql server 2000采用windows 身份验证后,如何用JDBC建立连接

来源:百度知道 编辑:UC知道 时间:2024/07/12 16:52:40
我在安装SQL server 2000 的时候选的是windows 身份验证,没有设置用户名和密码,然后我写了一个程序,结果连不上。程序如下:
<%@ page language="java" import="java.util.*"
import="com.mysql.jdbc.Driver" import="java.sql.*"
pageEncoding="utf-8" contentType="text/html;charset=gb2312"%>

<html>
<head>
</head>

<body>
<%
Connection conn;
Statement stat;

String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=student";
String userName="sa";
String password="";
try{

Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
}
catch(ClassNotFoundException ex){
out.println("找不到驱动程序!");}
conn=DriverManager.getConnection(url,userName,password);
try{
stat=conn.createStatement();
ResultSet result=stat.execut

String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=student";
String userName="sa";
String password="";
conn=DriverManager.getConnection(url);
兄弟你想想,你这样连接传递了用户名和密码吗?很明显没有吧?
改成 conn=DriverManager.getConnection(url,userName,password);
如果想用getConnection只含一个参数的方法,那你发参数带在url里。
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=student?userName='sa'&password=''"; (不敢确定是否正确)