Advertisement
Guest User

Untitled

a guest
Jun 6th, 2018
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.59 KB | None | 0 0
  1. import java.sql.*;
  2. import java.io.*;
  3. import java.lang.*;
  4. import java.util.*;
  5.  
  6. class Primer11 {
  7.  
  8.     static
  9.     {
  10.         try
  11.         {
  12.             Class.forName("com.ibm.db2.jcc.DB2Driver");
  13.         }
  14.         catch (Exception e)
  15.         {
  16.             e.printStackTrace();
  17.         }
  18.     }
  19.  
  20.     public static void main (String argv[])
  21.     {
  22.         try
  23.         {
  24.             Connection con = null;
  25.             String url = "jdbc:db2://localhost:50001/vstud";
  26.            
  27.             con = DriverManager.getConnection(url, "student", "abcdef");
  28.  
  29.             ResultSet rs = null;
  30.             String sql="SELECT * FROM ispitni_rok order by naziv";
  31.             PreparedStatement pstmt  = con.prepareStatement( sql, rs.TYPE_SCROLL_INSENSITIVE, rs.CONCUR_READ_ONLY );
  32.             rs = pstmt.executeQuery();
  33.  
  34.             rs.afterLast();
  35.  
  36.             System.out.println("+------+------+-------------------------+---------------+------------+---+");
  37.             System.out.println("|GODINA|OZNAKA|NAZIV                    |POCETAK PRIJAVE|KRAJ PRIJAVE|TIP|");
  38.  
  39.             while (rs.previous())
  40.             {
  41.                 System.out.println("|------+------+-------------------------+---------------+------------+---|");
  42.                 System.out.println("|" + rs.getInt(1) + "  |" + rs.getString(2) + "|" +rs.getString(3) + "|" + rs.getDate(4) + "     |" + rs.getDate(5) + "  |" + rs.getString(6) + "  |");
  43.                
  44.             }
  45.            
  46.             System.out.println("+------+------+-------------------------+---------------+------------+---+");
  47.  
  48.             rs.close();
  49.             pstmt.close();
  50.             con.close();
  51.         }
  52.         catch (SQLException e)
  53.         {
  54.             System.out.println("SQLCODE: " +e.getErrorCode() + "SQLSTATE: " + e.getSQLState() + "PORUKA: " + e.getMessage());
  55.         }
  56.         catch (Exception e)
  57.         {
  58.             e.printStackTrace();
  59.         }
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement