写成sa总是可以的吗?
我在sql server2000里建了一个ScienceManage数据库,然后建了一个database.properties文件,内容是
jdbc.drivers=com.microsoft.jdbc.sqlserver.SQLServerDriver
jdbc.url=jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=ScienceManage
jdbc.username=sa
jdbc.password=
然后运行TestDB.java文件,
import java.sql.*;
import java.io.*;
import java.util.*;/**
This program tests that the database and the JDBC
driver are correctly configured.
*/
class TestDB
{
public static void main (String args[])
{
try
{
Connection conn = getConnection();
Statement stat = conn.createStatement(); stat.execute("CREATE TABLE Greetings (Name CHAR(20))");
stat.execute(
"INSERT INTO Greetings VALUES ('Hello, World!')"); ResultSet result
= stat.executeQuery("SELECT * FROM Greetings");
result.next();
System.out.println(result.getString(1));
result.close(); stat.execute("DROP TABLE Greetings");
stat.close();
conn.close();
}
catch (SQLException ex)
{
while (ex != null)
{
ex.printStackTrace();
ex = ex.getNextException();
}
}
catch (IOException ex)
{
ex.printStackTrace();
}
} /**
Gets a connection from the properties specified
in the file database.properties
@return the database connection
*/
public static Connection getConnection()
throws SQLException, IOException
{
Properties props = new Properties();
FileInputStream in
= new FileInputStream("database.properties");
props.load(in);
in.close(); String drivers = props.getProperty("jdbc.drivers");
if (drivers != null)
System.setProperty("jdbc.drivers", drivers);
String url = props.getProperty("jdbc.url");
String username = props.getProperty("jdbc.username");
String password = props.getProperty("jdbc.password"); return
DriverManager.getConnection(url, username, password);
}
}运行后为什么是
---------- java ----------
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]用户 'sa' 登录失败。原因: 未与信任 SQL Server 连接相关联。
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processErrorToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReplyToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSLoginRequest.processReplyToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReply(Unknown Source)
at com.microsoft.jdbc.sqlserver.SQLServerImplConnection.open(Unknown Source)
at com.microsoft.jdbc.base.BaseConnection.getNewImplConnection(Unknown Source)
at com.microsoft.jdbc.base.BaseConnection.open(Unknown Source)
at com.microsoft.jdbc.base.BaseDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:512)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at TestDB.getConnection(TestDB.java:73)
at TestDB.main(TestDB.java:20)
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]An error occured while attempting to log onto the database.
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSLoginRequest.processReplyToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReply(Unknown Source)
at com.microsoft.jdbc.sqlserver.SQLServerImplConnection.open(Unknown Source)
at com.microsoft.jdbc.base.BaseConnection.getNewImplConnection(Unknown Source)
at com.microsoft.jdbc.base.BaseConnection.open(Unknown Source)
at com.microsoft.jdbc.base.BaseDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:512)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at TestDB.getConnection(TestDB.java:73)
at TestDB.main(TestDB.java:20)
我在sql server2000里建了一个ScienceManage数据库,然后建了一个database.properties文件,内容是
jdbc.drivers=com.microsoft.jdbc.sqlserver.SQLServerDriver
jdbc.url=jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=ScienceManage
jdbc.username=sa
jdbc.password=
然后运行TestDB.java文件,
import java.sql.*;
import java.io.*;
import java.util.*;/**
This program tests that the database and the JDBC
driver are correctly configured.
*/
class TestDB
{
public static void main (String args[])
{
try
{
Connection conn = getConnection();
Statement stat = conn.createStatement(); stat.execute("CREATE TABLE Greetings (Name CHAR(20))");
stat.execute(
"INSERT INTO Greetings VALUES ('Hello, World!')"); ResultSet result
= stat.executeQuery("SELECT * FROM Greetings");
result.next();
System.out.println(result.getString(1));
result.close(); stat.execute("DROP TABLE Greetings");
stat.close();
conn.close();
}
catch (SQLException ex)
{
while (ex != null)
{
ex.printStackTrace();
ex = ex.getNextException();
}
}
catch (IOException ex)
{
ex.printStackTrace();
}
} /**
Gets a connection from the properties specified
in the file database.properties
@return the database connection
*/
public static Connection getConnection()
throws SQLException, IOException
{
Properties props = new Properties();
FileInputStream in
= new FileInputStream("database.properties");
props.load(in);
in.close(); String drivers = props.getProperty("jdbc.drivers");
if (drivers != null)
System.setProperty("jdbc.drivers", drivers);
String url = props.getProperty("jdbc.url");
String username = props.getProperty("jdbc.username");
String password = props.getProperty("jdbc.password"); return
DriverManager.getConnection(url, username, password);
}
}运行后为什么是
---------- java ----------
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]用户 'sa' 登录失败。原因: 未与信任 SQL Server 连接相关联。
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processErrorToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReplyToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSLoginRequest.processReplyToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReply(Unknown Source)
at com.microsoft.jdbc.sqlserver.SQLServerImplConnection.open(Unknown Source)
at com.microsoft.jdbc.base.BaseConnection.getNewImplConnection(Unknown Source)
at com.microsoft.jdbc.base.BaseConnection.open(Unknown Source)
at com.microsoft.jdbc.base.BaseDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:512)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at TestDB.getConnection(TestDB.java:73)
at TestDB.main(TestDB.java:20)
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]An error occured while attempting to log onto the database.
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSLoginRequest.processReplyToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReply(Unknown Source)
at com.microsoft.jdbc.sqlserver.SQLServerImplConnection.open(Unknown Source)
at com.microsoft.jdbc.base.BaseConnection.getNewImplConnection(Unknown Source)
at com.microsoft.jdbc.base.BaseConnection.open(Unknown Source)
at com.microsoft.jdbc.base.BaseDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:512)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at TestDB.getConnection(TestDB.java:73)
at TestDB.main(TestDB.java:20)
解决方案 »
- 关于Java的使用
- 关于如果在jdk1.1环境下修改鼠标cussor
- 什么是工厂模式???????
- 从java.sun.com下载的J2EE SDK是否不包含JRE?
- 设置ClassLoader
- 请问如何让JFrame出现的时候最大化?
- 初学正则表达式,简单问题,在线等待
- My first Java PG :Anyone can help me to add the print function ?
- 请问怎么解决刷新问题???????????????????????????????????????????/
- 有谁知道java如何实现结构体吗?
- 更改JFrame和JInternalFrame标题栏颜色
- 谁有JDK?我的丢了,现在不好找回来
2.密码正确吗?
2.sql是用什么方式登陆