Biblioteca Java - Blame information for rev 35
Subversion Repositories:
Rev | Author | Line No. | Line |
---|---|---|---|
3 | mihai | 1 | /* |
2 | * TestModificaTabel.java | ||
3 | */ | ||
4 | package lab.scd.db.jdbc10; | ||
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 10, 2005. | ||
35 | mihai | 15 | * |
3 | mihai | 16 | * This class is part of the laborator4_db project. |
35 | mihai | 17 | * |
18 | * Pentru realizarea de modificari asupra bazei de date se foloseste metoda | ||
19 | * executeUpdate() din cadrul clasei Statement. | ||
20 | * | ||
3 | mihai | 21 | */ |
22 | public class TestModificaTabel { | ||
23 | |||
24 | public static void main(String[] args) { | ||
35 | mihai | 25 | try { |
26 | |||
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 | //contruieste un obiect de tip statement | ||
34 | Statement stat = conn.createStatement(); | ||
35 | |||
36 | String updateString = "UPDATE STOC " | ||
37 | + "SET PROD = 'prod modificat'" | ||
38 | + "WHERE PROD LIKE 'produs 1'"; | ||
39 | |||
40 | //modifica inregistrarile din tabel | ||
41 | stat.executeUpdate(updateString); | ||
42 | |||
43 | //afiseaza datele din tabel modificate | ||
44 | ResultSet rs = stat.executeQuery("SELECT * FROM STOC"); | ||
45 | |||
46 | while (rs.next()) { | ||
47 | String pname = rs.getString("PROD"); | ||
48 | int ppret = rs.getInt("PRET"); | ||
49 | System.out.println("Produs:" + pname + " Pret:" + ppret); | ||
50 | }//.while | ||
51 | |||
52 | } catch (Exception e) { | ||
3 | mihai | 53 | e.printStackTrace(); |
54 | } | ||
35 | mihai | 55 | |
3 | mihai | 56 | }//.main |
57 | } |