JDBC connection Url for SQLServer express R2

前端 未结 4 1726
鱼传尺愫
鱼传尺愫 2021-01-03 04:12

I wrote the below line for connection with sql server express r2:

Connection con=DriverManager.getConnection(\"jdbc:sqlserver://localhost/SQLEXPRESS;databaseName=abc

相关标签:
4条回答
  • 2021-01-03 04:48

    I also got the same problem in sqlserver2008. To resolve these issu follow the sets as below: Start sqlserver-> from login window select Options button-> Connection Properties-> Connect to Database-> Brows and select database name-> then below in Network protocol select TCP/IP. And do execute your program.

    0 讨论(0)
  • 2021-01-03 04:53

    Try to use your local machine's IP address instead of localhost.

    0 讨论(0)
  • 2021-01-03 04:56

    Try running some Java code to test it. Replace {computer-name}\SQLEXPRESS with the domain that you see in the root node of SQL Server Management Studio. When installing SQL Express, you had the option to change the name of "SQLEXPRESS" to something custom, so that might also be different. To get the port number, go to Windows Start Menu > SQL Server 2008 R2 > Configuration Tools > SQL Server Configuration Manager > expand "SQL Server Network Configuration" > Click "Protocols for SQLEXPRESS" > right click "TCP/IP" and choose Properties > click "IP Addresses" tab/menu > in Windows XP, you will see "IPAll" .. look at the port there. It should default to 1433. If you have 2 version of SQL Express, then it might be different. Also make sure your service is running (has status of "Started") in Windows Control Panel > Administrative Tools > Services > SQL Server (SQLEXPRESS). Windows 7 is slightly different, but you'll find it.

    The double backslashes need to be in a Java string. That just prints a single backslash during run time because it's an escape sequence.

    import java.sql.*;
    
    public class TestConnection
    {
        public static void main(String[] args)
        {
            DB db = new DB();
            db.dbConnect("jdbc:sqlserver://{computer-name}\\SQLEXPRESS:1433;databaseName=abc;integratedSecurity=true;","sa","password");
        }
    }
    
    class DB
    {
        public DB() {}
    
        public void dbConnect(String db_connect_string, String db_userid, String db_password)
        {
            try
            {
                Connection conn = DriverManager.getConnection(db_connect_string, db_userid, db_password);
                System.out.println("connected");
            }
            catch (Exception e)
            {
                e.printStackTrace();
            }
        }
    };
    
    0 讨论(0)
  • 2021-01-03 04:58

    For SQL Server > 2005 you have to start also the Sql Server Browser service.

    I've tested successfully JBoss 7 with Sql Server 2014 Express. OS: Windows 7. Settings I had to do for Sql Server:

    1. Enabled the TCPIP option in: SQL Server Configuration Manager -> Sql Server Network Configuration -> Protocols for servername
    2. Stopped the following 2 services and started them again:

      • Sql Server (servername)
      • Sql Server Browser

    I've used no port and also the local machine name in the URL.

    0 讨论(0)
提交回复
热议问题