Biblioteca Java - Blame information for rev 35
Subversion Repositories:
Rev | Author | Line No. | Line |
---|---|---|---|
3 | mihai | 1 | /* |
2 | * MutaCursor.java | ||
3 | */ | ||
4 | package lab.scd.db.jdb20; | ||
5 | |||
6 | import java.sql.Connection; | ||
7 | import java.sql.DriverManager; | ||
8 | import java.sql.ResultSet; | ||
9 | import java.sql.Statement; | ||
10 | |||
11 | import lab.scd.db.util.DBConfig; | ||
12 | |||
13 | /** | ||
14 | * Class created by @author Mihai HULEA at Mar 13, 2005. | ||
35 | mihai | 15 | * |
3 | mihai | 16 | * This class is part of the laborator4_db project. |
35 | mihai | 17 | * |
18 | * Exemplifica metodele de deplasare in cadrul unui ResultSet folosind | ||
19 | * facilitatile din JDBC 2.0 | ||
20 | * | ||
3 | mihai | 21 | */ |
22 | public class MutaCursor { | ||
23 | |||
24 | public static void main(String[] args) { | ||
35 | mihai | 25 | try { |
26 | //incarcare driver petru baza de date | ||
27 | Class.forName("org.apache.derby.jdbc.ClientDriver"); | ||
28 | |||
29 | //conectare la baza de date | ||
30 | Connection conn = DriverManager.getConnection("jdbc:derby://" + DBConfig.HOST + "/" + DBConfig.DATABASE, DBConfig.USER, DBConfig.PWD); | ||
31 | System.out.println("Conexiune la baza de date realizata."); | ||
32 | |||
33 | Statement s = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, | ||
34 | ResultSet.CONCUR_UPDATABLE); | ||
35 | |||
36 | //executa interogarea asupra bazei de date | ||
37 | ResultSet rs = s.executeQuery("SELECT * FROM STOC"); | ||
38 | |||
3 | mihai | 39 | //deplasare inainte |
35 | mihai | 40 | while (rs.next()) { |
41 | String pname = rs.getString("PROD"); | ||
42 | int ppret = rs.getInt("PRET"); | ||
43 | System.out.println("Produs:" + pname + " Pret:" + ppret); | ||
44 | } | ||
45 | |||
3 | mihai | 46 | //deplasare inapoi |
35 | mihai | 47 | rs.last(); |
48 | while (rs.previous()) { | ||
49 | String pname = rs.getString("PROD"); | ||
50 | int ppret = rs.getInt("PRET"); | ||
51 | System.out.println("* Produs:" + pname + " Pret:" + ppret); | ||
52 | } | ||
53 | |||
54 | //pozitionare directa | ||
55 | rs.absolute(3); | ||
3 | mihai | 56 | String pname = rs.getString("PROD"); |
57 | int ppret = rs.getInt("PRET"); | ||
35 | mihai | 58 | System.out.println("** Produs:" + pname + " Pret:" + ppret); |
3 | mihai | 59 | |
35 | mihai | 60 | //pozitionare reliativa fata de pozitia curenta |
61 | rs.relative(1); | ||
62 | pname = rs.getString("PROD"); | ||
63 | ppret = rs.getInt("PRET"); | ||
64 | System.out.println("*** Produs:" + pname + " Pret:" + ppret); | ||
65 | |||
66 | } catch (Exception e) { | ||
3 | mihai | 67 | e.printStackTrace(); |
68 | } | ||
69 | } | ||
70 | } |