Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package teatrconnect;
- import java.sql.*;
- public class TeatrConnect {
- public static void main(String[] args) {
- System.out.println("jdbc:sqlserver://KOMPUTER\\SQLEXPRESS:1433");
- String connectionString =
- "jdbc:sqlserver://KOMPUTER\\SQLEXPRESS:1433;"
- + "database=Teatr;"
- + "user=sa;"
- + "password=Czekolaada1;" ;
- // Zadeklarowanie obiektów JDBC
- Connection connection = null;
- Statement statement = null;
- ResultSet resultSet = null;
- try {
- connection = DriverManager.getConnection(connectionString);
- //polecenia SQL
- String selectSql = "SELECT * from Sala";
- statement = connection.createStatement();
- resultSet = statement.executeQuery(selectSql);
- // Wyświetlenie wyników
- while (resultSet.next())
- {
- System.out.println(resultSet.getString(2));
- }
- }
- catch (Exception e) {
- e.printStackTrace();
- }
- finally {
- if (resultSet != null) try { resultSet.close(); } catch(Exception e) {}
- if (statement != null) try { statement.close(); } catch(Exception e) {}
- if (connection != null) try { connection.close(); } catch(Exception e) {}
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement