1 package wrappers; 2 3 import java.sql.SQLException; 4 import java.util.Hashtable; 5 6 import javax.sql.DataSource; 7 8 import org.postgresql.jdbc2.optional.PoolingDataSource; 9 10 public class PostgresqlInterface extends JdbcInterface { PostgresqlInterface()11 public PostgresqlInterface() { 12 this(true); 13 } // end of constructor 14 PostgresqlInterface(boolean b)15 public PostgresqlInterface(boolean b) { 16 super(b); 17 18 if (dst == null) 19 dst = new Hashtable<String, DataSource>(); 20 21 } // end of constructor 22 23 @Override JdbcConnect(String[] parms, int fsize, boolean scrollable)24 public int JdbcConnect(String[] parms, int fsize, boolean scrollable) { 25 int rc = 0; 26 String url = parms[1]; 27 DataSource ds = null; 28 PoolingDataSource pds = null; 29 30 if (DEBUG) 31 System.out.println("Connecting to Postgresql data source"); 32 33 try { 34 CheckURL(url, "postgresql"); 35 36 if ((ds = dst.get(url)) == null) { 37 pds = new PoolingDataSource(); 38 pds.setUrl(url); 39 40 if (parms[2] != null) 41 pds.setUser(parms[2]); 42 43 if (parms[3] != null) 44 pds.setPassword(parms[3]); 45 46 ds = pds; 47 48 dst.put(url, ds); 49 } // endif ds 50 51 // Get a connection from the data source 52 conn = ds.getConnection(); 53 54 // Get the data base meta data object 55 dbmd = conn.getMetaData(); 56 57 // Get a statement from the connection 58 stmt = GetStmt(fsize, scrollable); 59 } catch (SQLException se) { 60 SetErrmsg(se); 61 rc = -2; 62 } catch( Exception e ) { 63 SetErrmsg(e); 64 rc = -3; 65 } // end try/catch 66 67 return rc; 68 } // end of JdbcConnect 69 70 } // end of class PostgresqlInterface 71