Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- public class zad1 {
- public static void main(String args[])
- {
- try{
- Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
- }
- catch (ClassNotFoundException e) {
- e.printStackTrace( );
- }
- String url = "jdbc:sqlserver://localhost:1433;database=Northwind;user=adam;password=1234;";
- try {
- Connection connection = DriverManager.getConnection(url);
- String SQL = "SELECT CustomerID, ContactName FROM Customers";
- Statement stmt = connection.createStatement();
- ResultSet rs = stmt.executeQuery(SQL);
- while (rs.next())
- {
- System.out.println(rs.getString(1) + " " + rs.getString(2));
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement