Biblioteca Java - Blame information for rev 3

Subversion Repositories:
Rev:
Rev Author Line No. Line
3 mihai 1 /*
2  * TestAdaugaTabel.java
3  */
4 package lab.scd.db.jdbc10;
5  
6 import java.sql.Connection;
7 import java.sql.DriverManager;
8 import java.sql.Statement;
9  
10 import lab.scd.db.util.DBConfig;
11  
12 /**
13  * Class created by @author Mihai HULEA at Mar 10, 2005.
14  *
15  * This class is part of the laborator4_db project.
16  *
17  */
18 public class TestAdaugaTabel {
19  
20  
21     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){
49             e.printStackTrace();
50         }
51      }
52 }