JDBC Jtds can't establish a connection

2019-07-15 15:59发布

问题:

I want to make a access to my sql database than is placed in ASUS\MSSQLSERVER1 and database names "Test" with access to user teste with password teste

in java code I coded this:

@Test
    public void TesteTemp() throws SQLException, InstantiationException, IllegalAccessException, ClassNotFoundException
    {
        Class.forName("net.sourceforge.jtds.jdbc.Driver").newInstance();
        String connString = "jdbc:jtds:sqlserver://ASUS/Test;instance=MSSQLSERVER1;user=teste;password=teste;";

        Connection conn = null;
        try{
            conn = DriverManager.getConnection(connString);
        }catch(SQLException ex){
            ex.printStackTrace();
        }
        conn.close();

    }

And I receive this error:

Server ASUS has no instance named MSSQLSERVER1.

It makes sense?

I have the MSSQLSERVER1 service running.

回答1:

i resolved the problem.. the code is ok, the problem was than protocols for tcp/ip and named pipes were disabled, i just activated them, now runs ok.. Sql Configuration Manager > Sql Server Network Configuration > Protocols for [Server_Name]



标签: java jdbc jtds