T-K-O-T
java sozluk kod kernel hsqLdb java
01: /**02: * HSQLDB.java
03: */
04: package Kernel;
05: import java.sql.Connection;
06: import java.sql.DriverManager;
07: import java.sql.ResultSet;
08: import java.sql.SQLException;
09: import java.sql.Statement;
10: /**
11: * Veritabanına bağlantı sağlayan sınıftır.
12: * @author Ömer Faruk Nemutlu - http://www.tkot.tr.gg/
13: */
14: public class HSQLDB {
15:
16: private Connection c;
17: private Statement s;
18:
19: /**
20: * Default constructor'in çalışmasıyla birlikte, önceden konumu belirtilmiş
21: * veritabanına bağlantı kurulur.
22: */
23: public HSQLDB( String file_address, String user_name, String password ) {
24:
25: try {
26: Class.forName( "org.hsqldb.jdbcDriver" );
27: //System.out.println( "SUCCESS: HSQLDB JDBC driver is loaded." );
28: }
29: catch (Exception e) {
30: System.err.println( "ERROR: Failed to load HSQLDB JDBC driver." );
31: System.err.println( e.toString( ) );
32: }
33:
34: try {
35: c = DriverManager.getConnection(
36: "jdbc:hsqldb:file:" + file_address, user_name, password );
37: s = c.createStatement();
38: //System.out.println("SUCCESS: Connection established.");
39: }
40: catch (SQLException ex) {
41: System.err.println(ex.toString());
42: System.err.println("ERROR: Failed to connect to database.");
43: }
44: }
45:
46: /**
47: * Mevcut bağlantıyı alır.
48: */
49: public Connection get_connection( ) {
50: return c;
51: }
52:
53:
54: /**
55: * Veritabanı bağlantısını kapatır. 'SHUTDOWN' komutu, veritabanının
56: * kapatılacağını belirten HyperSonic SQL'e özel bir komuttur.
57: */
58: public void close_connection( ) {
59: try {
60: s.execute( "SHUTDOWN" );
61: s.close( );
62: c.close( );
63: //System.out.println( "SUCCESS: Database connection closed." );
64: }
65: catch (SQLException ex) {
66: System.err.println( "ERROR: Failed to disconnect from database." );
67: }
68: finally {
69: s = null;
70: c = null;
71: }
72: }
73:
74: }