Advertisement
Guest User

Untitled

a guest
Mar 14th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. import java.sql.*;
  2.  
  3. public class zad1 {
  4.  
  5. public static void main(String args[])
  6. {
  7. try{
  8. Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
  9. }
  10. catch (ClassNotFoundException e) {
  11. e.printStackTrace( );
  12. }
  13. String url = "jdbc:sqlserver://localhost:1433;database=Northwind;user=adam;password=1234;";
  14. try {
  15. Connection connection = DriverManager.getConnection(url);
  16. String SQL = "SELECT CustomerID, ContactName FROM Customers";
  17. Statement stmt = connection.createStatement();
  18. ResultSet rs = stmt.executeQuery(SQL);
  19.  
  20. while (rs.next())
  21. {
  22. System.out.println(rs.getString(1) + " " + rs.getString(2));
  23. }
  24. } catch (SQLException e) {
  25. e.printStackTrace();
  26. }
  27. }
  28.  
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement