SHARE
TWEET

Untitled

a guest Jan 25th, 2020 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.company;
  2.  
  3. import java.sql.*;
  4.  
  5. public class Main {
  6.  
  7.     public static void main(String[] args) {
  8.         try {
  9.             Class.forName("org.postgresql.Driver");
  10.             Connection con;
  11.             con= DriverManager.getConnection("jdbc:postgresql://158.75.112.103:55655/stud2","stud2",
  12.                     "student");
  13.             Statement stmt = con.createStatement();
  14.             String sql;
  15.             sql =  "CREATE TABLE KAZgffdgdgfgZAK " +
  16.                     "(ID INT PRIMARY KEY     NOT NULL," +
  17.                     " NAME           TEXT    NOT NULL, " +
  18.                     " AGE            INT     NOT NULL, " +
  19.                     " ADDRESS        CHAR(50), " +
  20.                     " SALARY         REAL)";
  21.  
  22.             sql = "INSERT INTO KAfdgfdgAK (ID,NAME,AGE,ADDRESS,SALARY) "
  23.                     + "VALUES (1, 'Paul', 32, 'California', 20000.00 );";
  24.             stmt.executeUpdate(sql);
  25.  
  26.             sql = "INSERT INTO KAfdgfdgK (ID,NAME,AGE,ADDRESS,SALARY) "
  27.                     + "VALUES (2, 'Allen', 25, 'Texas', 15000.00 );";
  28.             stmt.executeUpdate(sql);
  29.  
  30.             sql = "INSERT INTO KfdgfdgfdgK(ID,NAME,AGE,ADDRESS,SALARY) "
  31.                     + "VALUES (3, 'Teddy', 23, 'Norway', 20000.00 );";
  32.             stmt.executeUpdate(sql);
  33.  
  34.             sql = "INSERT INTO KfdgfdgdfK (ID,NAME,AGE,ADDRESS,SALARY) "
  35.                     + "VALUES (4, 'Mark', 25, 'Rich-Mond ', 65000.00 );";
  36.             stmt.executeUpdate(sql);
  37.  
  38.  
  39.             ResultSet rs = stmt.executeQuery( "SELECT * FROM KAdfgfdgfdgdgdK;" );
  40.             while ( rs.next() ) {
  41.                 int id = rs.getInt("id");
  42.                 String  name = rs.getString("name");
  43.                 int age  = rs.getInt("age");
  44.                 String  address = rs.getString("address");
  45.                 float salary = rs.getFloat("salary");
  46.                 System.out.println( "ID = " + id );
  47.                 System.out.println( "NAME = " + name );
  48.                 System.out.println( "AGE = " + age );
  49.                 System.out.println( "ADDRESS = " + address );
  50.                 System.out.println( "SALARY = " + salary );
  51.                 System.out.println();
  52.             }
  53.             stmt.close();
  54.             con.close();
  55.         } catch (ClassNotFoundException e) {
  56.             e.printStackTrace();
  57.         } catch (SQLException e) {
  58.             e.printStackTrace();
  59.         }
  60.  
  61.     }
  62. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top