List of utility methods to do DataSource
Connection | getJNDIConnectionByContainer(String dataSource) GetConnection with jdbc/xxxDS try { Connection conn = null; InitialContext ctx = new InitialContext(); if (ctx != null) { Object o = ctx.lookup(dataSource); DataSource ds = (DataSource) o; conn = ds.getConnection(); return conn; } catch (Exception e) { e.printStackTrace(); return null; |
int | getProductAllCount(DataSource ds, String key, String sql_allcount) get Product All Count Connection c = null; PreparedStatement ps = null; ResultSet rs = null; int ret = 0; try { c = ds.getConnection(); ps = c.prepareStatement(sql_allcount, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); ps.setString(1, key); ... |
String | getSchemaSeparator(DataSource dataSource) Retrieve the schema separator for the database associated with the specified data source. try (Connection connection = dataSource.getConnection()) { DatabaseMetaData metaData = connection.getMetaData(); String schemaSeparator = metaData.getCatalogSeparator(); if ((schemaSeparator == null) || (schemaSeparator.length() == 0)) { schemaSeparator = "."; return schemaSeparator; |
int | getTableColumnCount(DataSource dataSource, String selectedTable) get Table Column Count Connection connection = null; ResultSet rs = null; try { connection = dataSource.getConnection(); DatabaseMetaData meta = connection.getMetaData(); rs = meta.getColumns(null, null, selectedTable, null); rs.last(); return rs.getRow(); ... |
List | getTables(DataSource datasource) get Tables if (_tnames != null) { return _tnames; _tnames = new CopyOnWriteArrayList<String>(); Connection conn = null; ResultSet rs = null; try { conn = datasource.getConnection(); ... |
boolean | hasTable(DataSource ds, String table) Checks if the given database contains a table with the given name. try (Connection conn = ds.getConnection()) { return hasTable(conn, table); |
void | initDataSource() init Data Source Context initContext = new InitialContext(); Context context = (Context) initContext.lookup("java:comp/env"); DataSource ds = (javax.sql.DataSource) context.lookup("jdbc/webrod"); dataSource = ds; |
DataSource | initDatasource(String jndiName) init Datasource try { javax.naming.Context ctx = new InitialContext(); javax.naming.Context envCtx = (javax.naming.Context) ctx.lookup("java:comp/env"); final DataSource ds = (DataSource) envCtx.lookup(jndiName); return new DataSource() { @Override public Connection getConnection() throws SQLException { Connection conn = ds.getConnection(); ... |
void | initDb(DataSource ds) Initialize the sample's database. createTables(ds); purgeTables(ds); |
void | initializeDataSource() initialize Data Source if (ussdDatasource != null) { return; String statdataSourceName = "jdbc/CONNECT_DB"; if (statdataSourceName != null) { try { Context ctx = new InitialContext(); ussdDatasource = (DataSource) ctx.lookup(statdataSourceName); ... |