KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > it > bigatti > c6 > BadgeDAO


1 /**
2  * BadgeDAO
3  */

4 package it.bigatti.c6;
5
6 import java.sql.Connection JavaDoc;
7 import java.sql.DriverManager JavaDoc;
8 import java.sql.ResultSet JavaDoc;
9 import java.sql.SQLException JavaDoc;
10 import java.sql.Statement JavaDoc;
11
12 /**
13  * @author max@bigatti.it
14  * Publications of same author on the italian magazine ioProgrammo.
15  * Forums at: http://forum.ioprogrammo.it
16  */

17 public class BadgeDAO {
18
19     Connection JavaDoc conn = null;
20     private static BadgeDAO instance = null;
21     
22     private BadgeDAO() throws SQLException JavaDoc, ClassNotFoundException JavaDoc {
23         //Class.forName("org.gjt.mm.mysql.Driver");
24
//conn = DriverManager.getConnection(
25
//"jdbc:mysql://10.254.120.100/c6","root","mysql");
26
}
27     
28     public static BadgeDAO getInstance()
29             throws SQLException JavaDoc, ClassNotFoundException JavaDoc {
30         if( instance == null ) {
31             instance = new BadgeDAO();
32         }
33         return instance;
34     }
35     
36     boolean verificaBadge( String JavaDoc badge ) throws SQLException JavaDoc {
37         /*
38         boolean result = false;
39         
40         String sql = "SELECT id FROM badges WHERE " +
41             " codice_badge='" + badge + "' AND" +
42             " data_scadenza>=NOW() AND" +
43             " valida=1";
44         System.out.println( sql );
45         
46         Statement stmt = null;
47         ResultSet rs = null;
48         
49         try {
50             stmt = conn.createStatement();
51             rs = stmt.executeQuery( sql );
52             result = rs.next();
53         } finally {
54             if (stmt != null ) {
55                 stmt.close();
56             }
57             if (rs != null ) {
58                 rs.close();
59             }
60         }
61         */

62         return true;
63     }
64
65     /** aggiunge una registrazione di ingresso */
66     void registra( String JavaDoc badge ) throws SQLException JavaDoc {
67         /*
68         String sql = "INSERT INTO registrazioni "+
69             "VALUES ('"+badge+"',NOW(),'E')";
70         System.out.println( sql );
71         
72         Statement stmt = null;
73         
74         try {
75             stmt = conn.createStatement();
76             stmt.execute( sql );
77         } finally {
78             if (stmt != null ) {
79                 stmt.close();
80             }
81         }
82         */

83     }
84
85     /** elimina il prefisso BADGE: dalla riga di testo ricevuta */
86     public static String JavaDoc badgeCode(String JavaDoc badgeLine) {
87         final String JavaDoc prefix = "BADGE: ";
88         String JavaDoc badge = badgeLine.substring(
89                 badgeLine.indexOf( prefix ) + prefix.length() );
90         return badge;
91     }
92 }
93
Popular Tags