Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package javasql;
- import java.sql.*;
- import java.util.*;
- public class Program {
- private static String url = "jdbc:sqlserver://localhost\SQLExpress;database=Northwind;integratedSecurity=true;";
- //private static String userName = "sa";
- //private static String password = "myPassword";
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- RunDemo();
- }
- public static void RunDemo() {
- try {
- Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
- Connection connection = DriverManager.getConnection(url);
- Statement statement = connection.createStatement();
- ResultSet results = statement.executeQuery("SELECT ProductName, Price FROM Products ORDER BY ProductName");
- while(results.next()) {
- System.out.println("Product Name: " + results.getNString("ProductName") + " Price: $" + results.getFloat("UnitPrice"));
- }
- } catch (ClassNotFoundException | SQLException ex) {
- System.out.println(ex.getMessage());
- }
- }
- }
- run:
- com.microsoft.sqlserver.jdbc.SQLServerDriver
- BUILD SUCCESSFUL (total time: 0 seconds)
- run:
- The connection to the host localhost, named instance SQLExpress failed.
- Error: "java.net.SocketTimeoutException: Receive timed out".
- Verify the server and instance names and check that no firewall is blocking UDP traffic to port 1434.
- For SQL Server 2005 or later, verify that the SQL Server Browser Service is running on the host.
- BUILD SUCCESSFUL (total time: 15 seconds)
- run:
- The TCP/IP connection to the host localhost, port 1433 has failed. Error: "Connection refused: connect. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.".
- BUILD SUCCESSFUL (total time: 15 seconds)
- run:
- Sep 21, 2012 11:33:16 AM com.microsoft.sqlserver.jdbc.AuthenticationJNI <clinit>
- WARNING: Failed to load the sqljdbc_auth.dll cause : no sqljdbc_auth in java.library.path
- This driver is not configured for integrated authentication. ClientConnectionId:577f359e-4774-45f3-96fb-588785911817
- BUILD SUCCESSFUL (total time: 14 seconds)
- Verify the server and instance names and check that no firewall is blocking
- UDP traffic to port 1434. For SQL Server 2005 or later,
- verify that the SQL Server Browser Service is running on the host
- String url = "jdbc:sqlserver://ABC\SQLEXPRESS;databaseName=xyz;portNumber=1433"
Add Comment
Please, Sign In to add comment