Biblioteca Java - Blame information for rev 3
Subversion Repositories:
Rev | Author | Line No. | Line |
---|---|---|---|
3 | mihai | 1 | /* |
2 | * StocTable.java | ||
3 | */ | ||
4 | package lab.scd.db.movecursor; | ||
5 | |||
6 | import java.sql.*; | ||
7 | |||
8 | import lab.scd.db.util.DBConfig; | ||
9 | |||
10 | /** | ||
11 | * Class created by @author Mihai HULEA at Mar 10, 2005. | ||
12 | * | ||
13 | * This class is part of the laborator4_db project. | ||
14 | * | ||
15 | */ | ||
16 | public class StocTable { | ||
17 | |||
18 | Connection conn; | ||
19 | Statement s; | ||
20 | ResultSet rs; | ||
21 | |||
22 | StocTable()throws Exception{ | ||
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 | |||
29 | System.out.println("Conexiune la baza de date realizata."); | ||
30 | |||
31 | s = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE); | ||
32 | |||
33 | updateCursor(); | ||
34 | } | ||
35 | |||
36 | public void updateCursor() throws SQLException{ | ||
37 | rs = s.executeQuery("SELECT * FROM STOC"); | ||
38 | } | ||
39 | |||
40 | public void next(StocJPanel p) throws SQLException{ | ||
41 | if(rs.isLast()==false){ | ||
42 | rs.next(); | ||
43 | p.setName(rs.getString("PROD")); | ||
44 | p.setPret(""+rs.getInt("PRET")); | ||
45 | } | ||
46 | } | ||
47 | |||
48 | public void previous(StocJPanel p) throws SQLException{ | ||
49 | if(rs.isFirst()==false){ | ||
50 | rs.previous(); | ||
51 | p.setName(rs.getString("PROD")); | ||
52 | p.setPret(""+rs.getInt("PRET")); | ||
53 | } | ||
54 | } | ||
55 | |||
56 | public void newRecord(StocJPanel p)throws SQLException { | ||
57 | rs.moveToInsertRow(); | ||
58 | |||
59 | rs.updateString("PROD",p.getName()); | ||
60 | rs.updateInt("PRET",Integer.parseInt(p.getPret())); | ||
61 | |||
62 | rs.insertRow(); | ||
63 | |||
64 | |||
65 | } | ||
66 | |||
67 | public void modifyRecord(StocJPanel p)throws SQLException { | ||
68 | |||
69 | rs.updateString("PROD",p.getName()); | ||
70 | rs.updateInt("PRET",Integer.parseInt(p.getPret())); | ||
71 | rs.updateRow(); | ||
72 | } | ||
73 | } |