Statistics
| Revision:

root / org.gvsig.jcrs / libJCRS / src-test / es / idr / test / connection / UsrConnection.java @ 38

History | View | Annotate | Download (1.37 KB)

1
package es.idr.test.connection;
2

    
3
import java.sql.Connection;
4
import java.sql.DriverManager;
5
import java.sql.SQLException;
6
import java.sql.Statement;
7

    
8
public class UsrConnection {
9

    
10
        Connection connect;
11
        
12
        public UsrConnection() {
13
                try {
14
                        Class.forName("org.hsqldb.jdbcDriver");
15
                } catch (ClassNotFoundException e) {
16
                        e.printStackTrace();
17
                }
18
                
19
                try {                        
20
                        connect =  DriverManager.getConnection("jdbc:hsqldb:file:/home/jlgomez/gvSIGF2/gt2-usr-hsql/src/org/geotools/referencing/factory/usr/usr", "sa", "");                        
21
                } catch (SQLException e1) {
22
                        e1.printStackTrace();
23
                }
24
        }
25
        
26
        public Connection getConnection(){
27
                return connect;
28
        }
29
        
30
        public void shutdown() throws SQLException {
31

    
32
        Statement st = connect.createStatement();
33

    
34
        // db writes out to files and performs clean shuts down
35
        // otherwise there will be an unclean shutdown
36
        // when program ends
37
        st.execute("SHUTDOWN");
38
        connect.close();    // if there are no other open connection
39
    }
40
        
41
        public synchronized void update(String expression) throws SQLException {
42

    
43
        Statement st = null;
44

    
45
        st = connect.createStatement();    // statements
46

    
47
        int i = st.executeUpdate(expression);    // run the query
48

    
49
        if (i == -1) {
50
            System.out.println("db error : " + expression);
51
        }
52

    
53
        st.close();
54
    }    
55
}