求助关于jdbc连接sql server的配置问题?

yuyong81 2004-05-02 01:02:37
编写jdbc程序需要配置jdbc.drivers,jdbc.url,jdbc.username,jdbc.password ,我想请教大家一下,这个jdbc.username应该怎么指定啊,我不知道哪个才是我的jdbc.username啊?
...全文
90 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
rainboy20024 2004-05-06
  • 打赏
  • 举报
回复
1.sql运行了吗?
2.密码正确吗?
2.sql是用什么方式登陆
yuyong81 2004-05-04
  • 打赏
  • 举报
回复
再顶!
yuyong81 2004-05-03
  • 打赏
  • 举报
回复
自己顶!
junxi 2004-05-02
  • 打赏
  • 举报
回复
友情up!!~~~~~~~~
yuyong81 2004-05-02
  • 打赏
  • 举报
回复
大家帮帮忙啊!
vongood 2004-05-02
  • 打赏
  • 举报
回复
帮看年
yuyong81 2004-05-02
  • 打赏
  • 举报
回复
写成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)
boy 2004-05-02
  • 打赏
  • 举报
回复
jdbc.username:sa
jdbc.password:
hui3zhihui 2004-05-02
  • 打赏
  • 举报
回复
最简单的就是sa

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧