Biblioteca Java - Blame information for rev 3
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. | ||
15 | * | ||
16 | * This class is part of the laborator4_db project. | ||
17 | * | ||
18 | * Pentru realizarea de modificari asupra bazei de date se foloseste metoda executeUpdate() | ||
19 | * din cadrul clasei Statement. | ||
20 | * | ||
21 | */ | ||
22 | public class TestModificaTabel { | ||
23 | |||
24 | public static void main(String[] args) { | ||
25 | try{ | ||
26 | |||
27 | //incarcare driver petru baza de date | ||
28 | Class.forName("com.mysql.jdbc.Driver"); | ||
29 | |||
30 | //conectare la baza de date | ||
31 | Connection conn = DriverManager.getConnection("jdbc:mysql://"+DBConfig.HOST+"/"+DBConfig.DATABASE+"?user="+DBConfig.USER+"&password="+DBConfig.PWD); | ||
32 | System.out.println("Conexiune la baza de date realizata."); | ||
33 | |||
34 | //contruieste un obiect de tip statement | ||
35 | Statement stat = conn.createStatement(); | ||
36 | |||
37 | String updateString = "UPDATE STOC "+ | ||
38 | "SET PROD = 'prod modificat'"+ | ||
39 | "WHERE PROD LIKE 'PRODUS A';"; | ||
40 | |||
41 | //modifica inregistrarile din tabel | ||
42 | stat.executeUpdate(updateString); | ||
43 | |||
44 | //afiseaza datele din tabel modificate | ||
45 | ResultSet rs = stat.executeQuery("SELECT * FROM STOC;"); | ||
46 | |||
47 | while(rs.next()){ | ||
48 | String pname = rs.getString("PROD"); | ||
49 | int ppret = rs.getInt("PRET"); | ||
50 | System.out.println("Produs:"+pname+" Pret:"+ppret); | ||
51 | }//.while | ||
52 | |||
53 | }catch(Exception e){ | ||
54 | e.printStackTrace(); | ||
55 | } | ||
56 | |||
57 | }//.main | ||
58 | } |