public ArrayList<ArrayList<String>> getDataForQuery(DBType dbType, String hostname, int portnumber, String username, String password, String tableName, String dBorSIDName) throws SQLException, ClassNotFoundException { Connection conn = getConnection(hostname, portnumber, username, password, dBorSIDName); return getDataForQuery(conn, tableName); }
public ArrayList<ArrayList<String>> getDataForTable(DBType dbType, String hostname, int portnumber, String username, String password, String tableName, String dBorSIDName) throws SQLException, ClassNotFoundException { Connection conn = getConnection(hostname, portnumber, username, password, dBorSIDName); return getDataForTable(conn, tableName); }
public ArrayList<String> getListOfTables(DBType dbType, String hostname, int portnumber, String username, String password, String dBorSIDName) throws SQLException, ClassNotFoundException { Connection conn = getConnection(hostname, portnumber, username, password, dBorSIDName); return getListOfTables(conn); }
public Connection getConnection(String hostname, int portnumber, String username, String password, String dBorSIDName) throws SQLException, ClassNotFoundException { String connectString = getConnectString(hostname, portnumber, username, password, dBorSIDName); logger.debug("Connect to:" + hostname + ":" +portnumber + "/" + dBorSIDName); logger.debug("Conn string:"+ connectString); Connection conn = getConnection(getDriver(), connectString); return conn; }
@Override public Worksheet generateWorksheet() throws KarmaException { /** * Get the data from the database table * */ AbstractJDBCUtil dbUtil = JDBCUtilFactory.getInstance(dbType); // TODO Limiting the number of rows to 1000 for now to avoid all data in memory ArrayList<ArrayList<String>> data; try { data = dbUtil.getDataForLimitedRows(dbType, hostname, portnumber, username, password, tableName, dBorSIDName, 100); } catch (SQLException | ClassNotFoundException e) { throw new KarmaException("Unable to get data for limited rows " + e.getLocalizedMessage()); } return generateWorksheet(dbUtil, data); }
/** * Returns true if given table exists in DB; false otherwise. * @param tableName * @param conn * @return * true if given table exists in DB; false otherwise. * @throws SQLException * @throws ClassNotFoundException */ public boolean tableExists(String tableName, Connection conn) throws SQLException, ClassNotFoundException { List<String> tn = getListOfTables(conn); if (tn.contains(tableName)) { return true; } return false; }
public Worksheet generateWorksheetForAllRows() throws SQLException, ClassNotFoundException { /** * Get the data from the database table * */ AbstractJDBCUtil dbUtil = JDBCUtilFactory.getInstance(dbType); ArrayList<ArrayList<String>> data = dbUtil.getDataForQuery(dbType, hostname, portnumber, username, password, query, dBorSIDName); return generateWorksheet(dbUtil, data); }
public Worksheet generateWorksheetForAllRows() throws SQLException, ClassNotFoundException { /** * Get the data from the database table * */ AbstractJDBCUtil dbUtil = JDBCUtilFactory.getInstance(dbType); ArrayList<ArrayList<String>> data = dbUtil.getDataForTable(dbType, hostname, portnumber, username, password, tableName, dBorSIDName); return generateWorksheet(dbUtil, data); }
Connection conn = dbUtil.getConnection(hostname, portnumber, username, password, dBorSIDName); conn.setAutoCommit(false); while ((rowValues = dbUtil.parseResultSetRow(r)) != null) {
protected String getConnectString (String hostname, int portnumber, String username, String password, String dBorSIDName) { String connectString = getConnectStringTemplate(); connectString = connectString.replaceAll("host", hostname); connectString = connectString.replaceAll("port", Integer.toString(portnumber)); connectString = connectString.replaceAll("dbname", dBorSIDName); connectString = connectString.replaceAll("username", username); //passwords could have special chars that are not being handles properly in //reg expr; so for pwd do the replace differently int pwdInd = connectString.indexOf("pwd"); if(pwdInd>=0){ connectString = connectString.substring(0,pwdInd)+password+connectString.substring(pwdInd+3); } return connectString; }
public void generateRDFFromTable(String tablename, String topkrows, List<KR2RMLRDFWriter> writers, R2RMLMappingIdentifier id, ContextIdentifier contextId, String baseURI) throws IOException, JSONException, KarmaException, SQLException, ClassNotFoundException { initializeWriter(id, contextId, writers); AbstractJDBCUtil dbUtil = JDBCUtilFactory.getInstance(dbType); String query = "Select * FROM " + dbUtil.escapeTablename(tablename); if (topkrows != null) { if (dbType == DBType.SQLServer) { query = "Select TOP " + topkrows + " * FROM " + dbUtil.escapeTablename(tablename); } else if (dbType == DBType.MySQL) { query = "Select * FROM " + dbUtil.escapeTablename(tablename) + " LIMIT " + topkrows; } else if (dbType == DBType.Oracle) { query = "Select * FROM " + dbUtil.escapeTablename(tablename) + " WHERE ROWNUM <= " + topkrows; } } generateRDF(tablename, query, writers, id, baseURI); }
@Override public Worksheet generateWorksheet() throws KarmaException { /** * Get the data from the database table * */ AbstractJDBCUtil dbUtil = JDBCUtilFactory.getInstance(dbType); // TODO Limiting the number of rows to 1000 for now to avoid all data in memory ArrayList<ArrayList<String>> data; try { data = dbUtil.getSQLQueryDataForLimitedRows(dbType, hostname, portnumber, username, password, query, dBorSIDName, 1000); return generateWorksheet(dbUtil, data); } catch (SQLException | ClassNotFoundException e) { //If data could not be imported, delete the empty worksheet Worksheet ws = getWorksheet(); if(ws != null) workspace.removeWorksheet(ws.getId()); throw new KarmaException("Unable to get data for the SQL Query: " + e.getMessage()); } }
AbstractJDBCUtil dbUtil = JDBCUtilFactory.getInstance(dbType); List<ArrayList<String>> data = dbUtil.getDataForLimitedRows(dbType, hostname, portnumber, username, password, tableName, dBorSIDName, 10);
AbstractJDBCUtil dbUtil = JDBCUtilFactory.getInstance(dbType); listOfTables = dbUtil.getListOfTables(dbType, hostname, portnumber, username, password, dBorSIDName);