Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) throws SQLException, IOException, Exception {
- Class.forName("org.postgresql.Driver");
- conn = DriverManager.getConnection("jdbc:postgresql://localhost:5432/postgres", "postgres", "postgres");
- System.out.println("OK. Database is on.");
- conn.setAutoCommit(false);
- statmt = conn.createStatement();
- statmt.executeUpdate("CREATE TABLE 'Strongy'");
- conn.commit();
- conn.setAutoCommit(true);
- statmt.execute("INSERT INTO TAD (number) VALUES ('Petya'); ");
- statmt.execute("INSERT INTO TAD (number) VALUES ('Vasya'); ");
- statmt.execute("INSERT INTO TAD (number) VALUES ('Masha'); ");
- System.out.println("Таблица создана или уже существует.");
- resSet = statmt.executeQuery("SELECT * FROM TAD");
- while(resSet.next())
- {
- int id = resSet.getInt("id");
- String name = resSet.getString("name");
- String phone = resSet.getString("phone");
- System.out.println( "ID = " + id );
- System.out.println( "name = " + name );
- System.out.println( "phone = " + phone );
- System.out.println();
- }
- System.out.println("Таблица выведена");
- conn.close();
- statmt.close();
- resSet.close();
- System.out.println("Соединения закрыты");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement