com.microsoft.sqlserver.jdbc.SQLServerException:连接字符串包含格式错误的名称或值

时间:2013-01-02 06:13:04

标签: java database-connection

我的代码是:

        try{
        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
        Connection con=DriverManager.getConnection("jdbc:sqlserver://localhost;jithin-pc:1433;databaseName=news;IntegratedSecurity=true");
        String qr="SELECT * FROM base";
        Statement st=con.createStatement();
        ResultSet rs=st.executeQuery(qr);
        rs.next();
        System.out.println(rs.getString(1));
        out.println(rs.getString(1));

        }
        catch(Exception e)
        {
            System.out.println(e);
            out.println(e);
        }

我收到如下错误:

com.microsoft.sqlserver.jdbc.SQLServerException: The connection string contains a badly formed name or value.

我尝试更改sql设置防火墙等。请提出任何建议

1 个答案:

答案 0 :(得分:0)

假设jithin-pc是localhost,那么localhost或jithin-pc就足够了。

jdbc:sqlserver://localhost;databaseName=news;IntegratedSecurity=true
jdbc:sqlserver://jithin-pc;databaseName=news;IntegratedSecurity=true

同时检查this