加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java.sql.SQLException:用户’admin’登录失败

发布时间:2020-12-15 04:24:25 所属栏目:Java 来源:网络整理
导读:免责声明:我之前从未使用过SQL服务器. 我正在尝试使用java代码连接到SQL Server Express. public class Test1 { public static void main(String[] args) throws SQLException,ClassNotFoundException { Class.forName("net.sourceforge.jtds.jdbc.Driver")
免责声明:我之前从未使用过SQL服务器.

我正在尝试使用java代码连接到SQL Server Express.

public class Test1 {

    public static void main(String[] args) throws SQLException,ClassNotFoundException {
        Class.forName("net.sourceforge.jtds.jdbc.Driver");
        String url = "jdbc:jtds:sqlserver://localhost:1433/POC;instance=MOHITCH-LAPTOP/SQLEXPRESS";
        String user = "admin";
        String password = "admin";
        Connection conn = DriverManager.getConnection(url,user,password);
        Statement st = conn.createStatement ();
            ResultSet rs = st.executeQuery("select * from POC.dbo.poc_table");
            while (rs.next())
            {
                System.out.println(rs.getInt(1) + " " + rs.getString(2));
            }
        }
    }

我得到了例外:

Exception in thread "main" java.sql.SQLException: Login failed for user 'admin'.
    at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:372)
    at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2820)
    at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2258)
    at net.sourceforge.jtds.jdbc.TdsCore.login(TdsCore.java:603)
    at net.sourceforge.jtds.jdbc.ConnectionJDBC2.<init>(ConnectionJDBC2.java:352)
    at net.sourceforge.jtds.jdbc.ConnectionJDBC3.<init>(ConnectionJDBC3.java:50)
    at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:185)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at java.sql.DriverManager.getConnection(Unknown Source)
    at my.java.Test1.main(Test1.java:16)

我也尝试使用MS SQL服务器Management Studio 2014登录.我成功地做到了.

这是我的数据库结构:

任何帮助都非常感谢!!
谢谢

解决方法

我认为您需要修改服务器中的某些配置.

请按照以下步骤操作,希望这对您有所帮助.

1. Open your SQL Server Management Studio.

2. Database server right click and go to properties.

3. Choose Security option and check SQL Server and Windows authentication mode.

4. Enable TCP/IP connection in SQL Configuration Manager.

5. Restart your SQL server service.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读