Statistics
| Revision:

root / branches / gvSIG_1.11.0_Mejoras_gvSIG-EIEL / libraries / libGDBMS / src / main / java / com / hardcode / gdbms / driver / postgresql / PostgreSQLDriver.java @ 34767

History | View | Annotate | Download (2.58 KB)

1
package com.hardcode.gdbms.driver.postgresql;
2

    
3
import java.sql.Connection;
4
import java.sql.DriverManager;
5
import java.sql.ResultSet;
6
import java.sql.SQLException;
7
import java.sql.Statement;
8
import java.util.ArrayList;
9

    
10
import com.hardcode.gdbms.engine.data.driver.AbstractJDBCDriver;
11
import com.iver.cit.gvsig.fmap.drivers.ITableDefinition;
12

    
13

    
14
/**
15
 *
16
 */
17
public class PostgreSQLDriver extends AbstractJDBCDriver {
18
    private static Exception driverException;
19

    
20
    static {
21
        try {
22
            Class.forName("org.postgresql.Driver").newInstance();
23
        } catch (Exception ex) {
24
            driverException = ex;
25
        }
26
    }
27

    
28

    
29
    /**
30
     * DOCUMENT ME!
31
     *
32
     * @param host DOCUMENT ME!
33
     * @param port DOCUMENT ME!
34
     * @param dbName DOCUMENT ME!
35
     * @param user DOCUMENT ME!
36
     * @param password DOCUMENT ME!
37
     *
38
     * @return DOCUMENT ME!
39
     *
40
     * @throws SQLException
41
     * @throws RuntimeException DOCUMENT ME!
42
     *
43
     * @see com.hardcode.gdbms.engine.data.driver.DBDriver#connect(java.lang.String)
44
     */
45
    public Connection getConnection(String host, int port, String dbName,
46
        String user, String password) throws SQLException {
47
        if (driverException != null) {
48
            throw new RuntimeException(driverException);
49
        }
50

    
51
        String connectionString = "jdbc:postgresql://" + host;
52

    
53
        if (port != -1) {
54
            connectionString += (":" + port);
55
        }
56

    
57
        connectionString += ("/" + dbName);
58

    
59
        if (user != null) {
60
            connectionString += ("?user=" + user + "&password=" + password);
61
        }
62

    
63
        return DriverManager.getConnection(connectionString);
64
    }
65

    
66
    /**
67
     * @see com.hardcode.driverManager.Driver#getName()
68
     */
69
    public String getName() {
70
        return "PostgreSQL Alphanumeric";
71
    }
72
    
73
        public String getDefaultPort() {
74
                return "5432";
75
        }
76
        
77
//        public String[] getAvailableTables(
78
//                        Connection co,
79
//                        String schema) throws SQLException {
80
//                
81
//                String sql = "select c.relname FROM pg_catalog.pg_class c " +
82
//                "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace " +
83
//                "WHERE c.relkind IN ('r','v','') AND n.nspname = '" + schema + "' " +
84
//                "AND pg_catalog.pg_table_is_visible(c.oid);";
85
//                
86
//                Statement st = co.createStatement(ResultSet.TYPE_FORWARD_ONLY,
87
//                                ResultSet.CONCUR_READ_ONLY);
88
//                ResultSet res = st.executeQuery(sql);
89
//                
90
//                ArrayList str_list = new ArrayList();
91
//                while (res.next()) {
92
//                        str_list.add(res.getString(1));
93
//                }
94
//                res.close();
95
//                st.close();
96
//                return (String[]) str_list.toArray(new String[0]) ;
97
//        }
98

    
99

    
100

    
101

    
102

    
103

    
104
}
105

    
106
// [eiel-gestion-conexiones]