Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- import java.io.*;
- import java.lang.*;
- import java.util.*;
- class Primer11 {
- static
- {
- try
- {
- Class.forName("com.ibm.db2.jcc.DB2Driver");
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
- public static void main (String argv[])
- {
- try
- {
- Connection con = null;
- String url = "jdbc:db2://localhost:50001/vstud";
- con = DriverManager.getConnection(url, "student", "abcdef");
- ResultSet rs = null;
- String sql="SELECT * FROM ispitni_rok order by naziv";
- PreparedStatement pstmt = con.prepareStatement( sql, rs.TYPE_SCROLL_INSENSITIVE, rs.CONCUR_READ_ONLY );
- rs = pstmt.executeQuery();
- rs.afterLast();
- System.out.println("+------+------+-------------------------+---------------+------------+---+");
- System.out.println("|GODINA|OZNAKA|NAZIV |POCETAK PRIJAVE|KRAJ PRIJAVE|TIP|");
- while (rs.previous())
- {
- System.out.println("|------+------+-------------------------+---------------+------------+---|");
- System.out.println("|" + rs.getInt(1) + " |" + rs.getString(2) + "|" +rs.getString(3) + "|" + rs.getDate(4) + " |" + rs.getDate(5) + " |" + rs.getString(6) + " |");
- }
- System.out.println("+------+------+-------------------------+---------------+------------+---+");
- rs.close();
- pstmt.close();
- con.close();
- }
- catch (SQLException e)
- {
- System.out.println("SQLCODE: " +e.getErrorCode() + "SQLSTATE: " + e.getSQLState() + "PORUKA: " + e.getMessage());
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement