Guest User

Untitled

a guest
Oct 4th, 2018
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. package javasql;
  2. import java.sql.*;
  3. import java.util.*;
  4.  
  5. public class Program {
  6.  
  7. private static String url = "jdbc:sqlserver://localhost\SQLExpress;database=Northwind;integratedSecurity=true;";
  8. //private static String userName = "sa";
  9. //private static String password = "myPassword";
  10.  
  11. /**
  12. * @param args the command line arguments
  13. */
  14. public static void main(String[] args) {
  15. RunDemo();
  16. }
  17.  
  18. public static void RunDemo() {
  19. try {
  20. Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
  21. Connection connection = DriverManager.getConnection(url);
  22.  
  23. Statement statement = connection.createStatement();
  24. ResultSet results = statement.executeQuery("SELECT ProductName, Price FROM Products ORDER BY ProductName");
  25.  
  26. while(results.next()) {
  27. System.out.println("Product Name: " + results.getNString("ProductName") + " Price: $" + results.getFloat("UnitPrice"));
  28. }
  29.  
  30. } catch (ClassNotFoundException | SQLException ex) {
  31. System.out.println(ex.getMessage());
  32. }
  33. }
  34. }
  35.  
  36. run:
  37. com.microsoft.sqlserver.jdbc.SQLServerDriver
  38. BUILD SUCCESSFUL (total time: 0 seconds)
  39.  
  40. run:
  41. The connection to the host localhost, named instance SQLExpress failed.
  42.  
  43. Error: "java.net.SocketTimeoutException: Receive timed out".
  44.  
  45. Verify the server and instance names and check that no firewall is blocking UDP traffic to port 1434.
  46. For SQL Server 2005 or later, verify that the SQL Server Browser Service is running on the host.
  47. BUILD SUCCESSFUL (total time: 15 seconds)
  48.  
  49. run:
  50. 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.".
  51. BUILD SUCCESSFUL (total time: 15 seconds)
  52.  
  53. run:
  54. Sep 21, 2012 11:33:16 AM com.microsoft.sqlserver.jdbc.AuthenticationJNI <clinit>
  55. WARNING: Failed to load the sqljdbc_auth.dll cause : no sqljdbc_auth in java.library.path
  56. This driver is not configured for integrated authentication. ClientConnectionId:577f359e-4774-45f3-96fb-588785911817
  57. BUILD SUCCESSFUL (total time: 14 seconds)
  58.  
  59. Verify the server and instance names and check that no firewall is blocking
  60. UDP traffic to port 1434. For SQL Server 2005 or later,
  61. verify that the SQL Server Browser Service is running on the host
  62.  
  63. String url = "jdbc:sqlserver://ABC\SQLEXPRESS;databaseName=xyz;portNumber=1433"
Add Comment
Please, Sign In to add comment