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