Biblioteca Java - Diff between revs 3 and 35
Subversion Repositories:
Rev 3 | Rev 35 | |||
---|---|---|---|---|
Line 9... | Line 9... | |||
9 | 9 | |||
10 | import lab.scd.db.util.DBConfig; | 10 | import lab.scd.db.util.DBConfig; | |
11 | 11 | |||
12 | /** | 12 | /** | |
13 | * Class created by @author Mihai HULEA at Mar 10, 2005. | 13 | * Class created by @author Mihai HULEA at Mar 10, 2005. | |
14 | * | - | ||
- | 14 | * | ||
15 | * This class is part of the laborator4_db project. | 15 | * This class is part of the laborator4_db project. | |
16 | * | - | ||
- | 16 | * | ||
17 | */ | 17 | */ | |
18 | public class TestAdaugaTabel { | 18 | public class TestAdaugaTabel { | |
19 | 19 | |||
20 | - | |||
21 | public static void main(String[] args) { | 20 | public static void main(String[] args) { | |
22 | try{ | - | ||
23 | //incarcare driver petru baza de date | - | ||
24 | Class.forName("com.mysql.jdbc.Driver"); | - | ||
25 | - | |||
26 | //conectare la baza de date | - | ||
27 | Connection conn = DriverManager.getConnection("jdbc:mysql://"+DBConfig.HOST+"/"+DBConfig.DATABASE+"?user="+DBConfig.USER+"&password="+DBConfig.PWD); | - | ||
28 | System.out.println("Conexiune la baza de date realizata."); | - | ||
29 | - | |||
30 | /** | - | ||
31 | * Pentru a efectua iperatii asupra bazei de date este nevoie de un obiect | - | ||
32 | * de tip Statement. | - | ||
33 | */ | - | ||
34 | Statement stat = conn.createStatement(); | - | ||
35 | - | |||
36 | //aduaga tabelul stoc cu doua campuri (prod si pret) | - | ||
37 | stat.executeUpdate("CREATE TABLE STOC (PROD VARCHAR(32), PRET INTEGER)"); | - | ||
38 | System.out.println("Tabel creat."); | - | ||
39 | - | |||
40 | //adauga doua produse in tabel | - | ||
41 | stat.executeUpdate("INSERT INTO STOC VALUES ('produs 1' , 2500)"); | - | ||
42 | stat.executeUpdate("INSERT INTO STOC VALUES ('produs 2' , 7900)"); | - | ||
43 | - | |||
44 | System.out.println("Date inserate in tabel."); | - | ||
45 | - | |||
46 | - | |||
47 | conn.close(); | - | ||
48 | }catch(Exception e){ | - | ||
- | 21 | try { | ||
- | 22 | Class.forName("org.apache.derby.jdbc.ClientDriver"); | ||
- | 23 | |||
- | 24 | //conectare la baza de date | ||
- | 25 | Connection conn = DriverManager.getConnection("jdbc:derby://" + DBConfig.HOST + "/" + DBConfig.DATABASE, DBConfig.USER, DBConfig.PWD); | ||
- | 26 | System.out.println("Conexiune la baza de date realizata."); | ||
- | 27 | |||
- | 28 | /** | ||
- | 29 | * Pentru a efectua iperatii asupra bazei de date este nevoie de un | ||
- | 30 | * obiect de tip Statement. | ||
- | 31 | */ | ||
- | 32 | Statement stat = conn.createStatement(); | ||
- | 33 | |||
- | 34 | //aduaga tabelul stoc cu doua campuri (prod si pret) | ||
- | 35 | stat.executeUpdate("CREATE TABLE STOC (PROD VARCHAR(32), PRET INTEGER)"); | ||
- | 36 | System.out.println("Tabel creat."); | ||
- | 37 | |||
- | 38 | //adauga doua produse in tabel | ||
- | 39 | stat.executeUpdate("INSERT INTO STOC VALUES ('produs 1' , 2500)"); | ||
- | 40 | stat.executeUpdate("INSERT INTO STOC VALUES ('produs 2' , 7900)"); | ||
- | 41 | |||
- | 42 | System.out.println("Date inserate in tabel."); | ||
- | 43 | |||
- | 44 | conn.close(); | ||
- | 45 | } catch (Exception e) { | ||
49 | e.printStackTrace(); | 46 | e.printStackTrace(); | |
50 | } | 47 | } | |
51 | } | - | ||
- | 48 | } | ||
52 | } | 49 | } |