
Connect to a named database: testdb on localhost by using the Windows authentication. Jdbc:sqlserver://dbHost\sqlexpress user=sa password=secret Connect to an instance named: sqlexpress on the host dbServer by using the SQL Server authentication. Jdbc:sqlserver://localhost integratedSecurity=true Connect to a default instance of SQL server running on the same machine as the JDBC client by using Windows authentication. Here in this mode, we have to explicitly specify the username and password. SQL Server Authentication: In this mode, we are using the SQL Server account to authenticate with the database. We specify this mode by adding the property integratedSecurity=true to the url. Windows Authentication: This mode is used for the case when both client and the SQL server are running on the same machine. Note: Microsoft SQL Server supports two authentication modes i.e.: To see the properties specific to the SQL server, visit this link. property=value: This parameter specifies one or more additional connection properties. In case this parameter is missing, the default port is used. portNumber: The default port number for connecting to SQL server 1433. If this parameter is not specified, the default instance is used. instanceName: Name of the instance to connect to on a serverName.
serverName: Host name or the IP address of the machine on which SQL server is running. The syntax of database URL for the SQL Server is as follows:
Automatic Loading of the Driver Interface.It provides the following advance features:
JDBC 4.0 is a new specification for JDBC. String name = resObj.getString("test_name") įloat salary = resObj.getFloat("test_salary") ResultSet resObj = stmtObj.executeQuery("SELECT test_id, test_name, test_salary FROM testTable") Statement stmtObj = connObj.createStatement() The following simple code fragment gives an example of these three steps:Įxample.java Connection connObj = DriverManager.getConnection("jdbc:myDriver:testDb", "myLoginId", "myPassword")
Retrieving and processing the results received from the database in answer to the SQL query. Sending queries and update statements to the database. JDBC lets a developer manage the below three important programming activities, i.e.: 1: Java Database Connectivity (JDBC) Architecture