Biblioteca Java - Blame information for rev 3

Subversion Repositories:
Rev:
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.
15  *
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  *
21  */
22 public class MutaCursor {
23  
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  
40         //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  
48         //deplasare inapoi
49  
50         rs.last();
51         while(rs.previous()){
52             String pname = rs.getString("PROD");
53             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);
68  
69  
70         }catch(Exception e){
71             e.printStackTrace();
72         }
73     }
74 }