source: DCWoRMS/branches/coolemall/src/test/drs_tst/recs/utils/db/SQLLiteManager.java @ 1120

Revision 1120, 1.3 KB checked in by dresiu, 12 years ago (diff)

dresiu init commit

Line 
1package test.drs_tst.recs.utils.db;
2
3import java.sql.Connection;
4import java.sql.DriverManager;
5import java.sql.ResultSet;
6import java.sql.SQLException;
7import java.sql.Statement;
8
9public class SQLLiteManager {
10
11        private static SQLLiteManager instance;
12
13        public static String DB_PATH = "src/test/drs_tst/recs/data/all_db";
14
15        private Connection connection;
16
17        private SQLLiteManager() {
18                connection = null;
19                try {
20                        // create a database connection
21                        Class.forName("org.sqlite.JDBC");
22                        connection = DriverManager.getConnection("jdbc:sqlite:" + DB_PATH);
23                        System.out.println(connection);
24                } catch (ClassNotFoundException e1) {
25                        // TODO Auto-generated catch block
26                        e1.printStackTrace();
27                } catch (SQLException e) {
28                        // if the error message is "out of memory",
29                        // it probably means no database file is found
30                        System.err.println(e.getMessage());
31                } 
32        }
33
34        public static SQLLiteManager getManager() {
35                if (instance == null) {
36                        instance = new SQLLiteManager();
37                }
38                return instance;
39        }
40
41        public ResultSet executeQuery(String query) {
42                Statement statement;
43                try {
44                        statement = connection.createStatement();
45                        //statement.setQueryTimeout(30);
46                        return statement.executeQuery(query);
47                } catch (SQLException e) {
48                        // TODO Auto-generated catch block
49                        e.printStackTrace();
50                        return null;
51                }
52
53        }
54}
Note: See TracBrowser for help on using the repository browser.