@Override public ArrayList<ArrayList<String>> getDataForLimitedRows(DBType dbType, String hostname, int portnumber, String username, String password, String tableName, String dBorSIDName, int rowCount) throws SQLException, ClassNotFoundException { String connectString = getConnectString(hostname, portnumber, username, password, dBorSIDName); Connection conn = getConnection(DRIVER, connectString); String query = "Select * from " + escapeTablename(tableName) + " limit " + rowCount; logger.info("Execute:" + query); Statement s = conn.createStatement(); ResultSet r = s.executeQuery(query); if (r == null) { s.close(); return null; } ArrayList<ArrayList<String>> vals = parseResultSetIntoArrayListOfRows(r); r.close(); s.close(); return vals; }
@Override public ArrayList<ArrayList<String>> getSQLQueryDataForLimitedRows(DBType dbType, String hostname, int portnumber, String username, String password, String query, String dBorSIDName, int rowCount) throws SQLException, ClassNotFoundException { String connectString = getConnectString(hostname, portnumber, username, password, dBorSIDName); Connection conn = getConnection(DRIVER, connectString); if(query.toLowerCase().indexOf(" limit ") == -1) //Add limit only if it doesnt exist, else sql will be invalid query = query + " limit " + rowCount; logger.info("Execute:" + query); Statement s = conn.createStatement(); ResultSet r = s.executeQuery(query); if (r == null) { s.close(); return null; } ArrayList<ArrayList<String>> vals = parseResultSetIntoArrayListOfRows(r); r.close(); s.close(); return vals; }
public static AbstractJDBCUtil getInstance(DBType dbType) { if(dbType == DBType.MySQL) return new MySQLUtil(); else if(dbType == DBType.Oracle) return new OracleUtil(); else if(dbType == DBType.SQLServer) return new SQLServerUtil(); else if(dbType == DBType.PostGIS) return new PostGISUtil(); else if(dbType == DBType.Sybase) return new SybaseUtil(); else return null; }