List of usage examples for java.sql ResultSet getString
String getString(String columnLabel) throws SQLException;
ResultSet
object as a String
in the Java programming language. From source file:com.sql.SECExceptions.java
/** * Gathers a list of errors based on type and count total of them. * * @return//from w w w. j a v a 2 s . c o m */ public static List<SystemErrorModel> getErrorCounts() { List<SystemErrorModel> list = new ArrayList(); Connection conn = null; PreparedStatement ps = null; ResultSet rs = null; try { conn = DBConnection.connectToDB(); String sql = "SELECT exceptionType, COUNT(*) AS 'num' " + "FROM SECExceptions " + "WHERE timeOccurred >= CAST(CURRENT_TIMESTAMP AS DATE) " + "GROUP BY exceptionType"; ps = conn.prepareStatement(sql); rs = ps.executeQuery(); while (rs.next()) { SystemErrorModel item = new SystemErrorModel(); item.setExceptionType(rs.getString("exceptionType") == null ? "" : rs.getString("exceptionType")); item.setNumber(rs.getInt("num")); list.add(item); } } catch (SQLException ex) { ExceptionHandler.Handle(ex); } finally { DbUtils.closeQuietly(conn); DbUtils.closeQuietly(ps); DbUtils.closeQuietly(rs); } return list; }
From source file:com.mycompany.rproject.runnableClass.java
public static void use() throws IOException { AWSCredentials awsCreds = new PropertiesCredentials( new File("/Users/paulamontojo/Desktop/AwsCredentials.properties")); AmazonSQS sqs = new AmazonSQSClient(awsCreds); Region usWest2 = Region.getRegion(Regions.US_WEST_2); sqs.setRegion(usWest2);/*from w w w . j av a 2 s.c o m*/ String myQueueUrl = "https://sqs.us-west-2.amazonaws.com/711690152696/MyQueue"; System.out.println("Receiving messages from MyQueue.\n"); ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest(myQueueUrl); List<Message> messages = sqs.receiveMessage(receiveMessageRequest).getMessages(); while (messages.isEmpty()) { messages = sqs.receiveMessage(receiveMessageRequest).getMessages(); } String messageRecieptHandle = messages.get(0).getReceiptHandle(); String a = messages.get(0).getBody(); sqs.deleteMessage(new DeleteMessageRequest(myQueueUrl, messageRecieptHandle)); //aqui opero y cuando acabe llamo para operar el siguiente. String n = ""; String dbName = "mydb"; String userName = "pmontojo"; String password = "pmontojo"; String hostname = "mydb.cued7orr1q2t.us-west-2.rds.amazonaws.com"; String port = "3306"; String jdbcUrl = "jdbc:mysql://" + hostname + ":" + port + "/" + dbName + "?user=" + userName + "&password=" + password; Connection conn = null; Statement setupStatement = null; Statement readStatement = null; ResultSet resultSet = null; String results = ""; int numresults = 0; String statement = null; try { conn = DriverManager.getConnection(jdbcUrl); setupStatement = conn.createStatement(); String insertUrl = "select video_name from metadata where id = " + a + ";"; String checkUrl = "select url from metadata where id = " + a + ";"; ResultSet rs = setupStatement.executeQuery(insertUrl); rs.next(); System.out.println("este es el resultdo " + rs.getString(1)); String names = rs.getString(1); ResultSet ch = setupStatement.executeQuery(checkUrl); ch.next(); System.out.println("este es la url" + ch.getString(1)); String urli = ch.getString(1); while (urli == null) { ResultSet sh = setupStatement.executeQuery(checkUrl); sh.next(); System.out.println("este es la url" + sh.getString(1)); urli = sh.getString(1); } setupStatement.close(); AmazonS3 s3Client = new AmazonS3Client(awsCreds); S3Object object = s3Client.getObject(new GetObjectRequest(bucketName, names)); IOUtils.copy(object.getObjectContent(), new FileOutputStream(new File("/Users/paulamontojo/Desktop/download.avi"))); putOutput(); write(); putInDb(sbu.toString(), a); } catch (SQLException ex) { // handle any errors System.out.println("SQLException: " + ex.getMessage()); System.out.println("SQLState: " + ex.getSQLState()); System.out.println("VendorError: " + ex.getErrorCode()); } finally { System.out.println("Closing the connection."); if (conn != null) try { conn.close(); } catch (SQLException ignore) { } } use(); }
From source file:gridool.db.helpers.GridDbUtils.java
/** * @return column position is not provided in the returning foreign keys *///from w ww . ja v a 2 s. com @Nonnull public static Collection<ForeignKey> getExportedKeys(@Nonnull final Connection conn, @Nullable final String pkTableName, final boolean setColumnPositions) throws SQLException { DatabaseMetaData metadata = conn.getMetaData(); String catalog = conn.getCatalog(); final Map<String, ForeignKey> mapping = new HashMap<String, ForeignKey>(4); final ResultSet rs = metadata.getExportedKeys(catalog, null, pkTableName); try { while (rs.next()) { final String fkName = rs.getString("FK_NAME"); ForeignKey fk = mapping.get(fkName); if (fk == null) { String fkTableName = rs.getString("FKTABLE_NAME"); fk = new ForeignKey(fkName, fkTableName, pkTableName); mapping.put(fkName, fk); } fk.addColumn(rs, metadata); } } finally { rs.close(); } final Collection<ForeignKey> fkeys = mapping.values(); if (setColumnPositions) { for (ForeignKey fk : fkeys) { fk.setColumnPositions(metadata); } } return fkeys; }
From source file:com.tfm.utad.sqoopdata.SqoopVerticaDB.java
private static void findBetweenMinIDAndMaxID(Connection conn, Long minID, Long maxID) { Statement stmt = null;/*w ww . j a v a2s .c om*/ String query; try { stmt = conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); query = "SELECT * FROM s1.coordinates WHERE id > " + minID + " AND id <= " + maxID + ""; LOG.info("Query execution: " + query); ResultSet rs = stmt.executeQuery(query); int batch = 0; List<CoordinateCartoDB> result = new ArrayList<>(); long start_time = System.currentTimeMillis(); while (rs.next()) { batch++; CoordinateCartoDB cdb = new CoordinateCartoDB((long) rs.getInt("id"), rs.getString("userstr"), rs.getString("created_date"), rs.getString("activity"), rs.getFloat("latitude"), rs.getFloat("longitude"), (long) rs.getInt("userid")); result.add(cdb); if (batch == 50) { sendDataToCartoDB(result); batch = 0; result = new ArrayList<>(); } } if (batch > 0) { sendDataToCartoDB(result); } long end_time = System.currentTimeMillis(); long difference = end_time - start_time; LOG.info("CartoDB API execution time: " + String.format("%d min %d sec", TimeUnit.MILLISECONDS.toMinutes(difference), TimeUnit.MILLISECONDS.toSeconds(difference) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(difference)))); } catch (SQLException e) { LOG.error("SQLException error: " + e.toString()); } finally { if (stmt != null) { try { stmt.close(); } catch (SQLException ex) { LOG.error("Statement error: " + ex.toString()); } } if (conn != null) { try { conn.close(); } catch (SQLException ex) { LOG.error("Connection error: " + ex.toString()); } } } }
From source file:gridool.db.helpers.GridDbUtils.java
/** * @return column position is provided in the returning foreign keys *//* w ww . j a va 2s.co m*/ @Nonnull public static Collection<ForeignKey> getForeignKeys(@Nonnull final Connection conn, @Nullable final String fkTableName, final boolean setColumnPositions) throws SQLException { DatabaseMetaData metadata = conn.getMetaData(); String catalog = conn.getCatalog(); final Map<String, ForeignKey> mapping = new HashMap<String, ForeignKey>(4); final ResultSet rs = metadata.getImportedKeys(catalog, null, fkTableName); try { while (rs.next()) { final String fkName = rs.getString("FK_NAME"); ForeignKey fk = mapping.get(fkName); if (fk == null) { //String fkTableName = rs.getString("FKTABLE_NAME"); String pkTableName = rs.getString("PKTABLE_NAME"); fk = new ForeignKey(fkName, fkTableName, pkTableName); mapping.put(fkName, fk); } fk.addColumn(rs, metadata); } } finally { rs.close(); } final Collection<ForeignKey> fkeys = mapping.values(); if (setColumnPositions) { for (ForeignKey fk : fkeys) { fk.setColumnPositions(metadata); } } return fkeys; }
From source file:com.hp.test.framework.generatejellytess.GenerateJellyTests.java
public static void exemappingmodel() { boolean clean_files = false; Map<Integer, String> Master_ModelList = new HashMap<Integer, String>(); try {/*w w w . j a va 2 s . c o m*/ Class.forName("org.sqlite.JDBC"); log.info("TestCase DB Location" + mp.getProperty("MODEL_DB_LOCATION")); alm_test_location = mp.getProperty("ALM_FORMAT_STORE_LOC"); Jelly_Tests_location = mp.getProperty("JELLY_TESTS_LOCATION"); CLEAN_JELLY_TESTS = mp.getProperty("CLEAN_JELLY_TESTS"); if (CLEAN_JELLY_TESTS.toLowerCase().equals("yes")) { clean_files = true; } connection = DriverManager.getConnection("jdbc:sqlite:" + mp.getProperty("MODEL_DB_LOCATION")); // int GID_int = Integer.parseInt(GID); Statement Master_statement = connection.createStatement(); ResultSet rs_master = Master_statement.executeQuery( "SELECT GID,FEATURENAME FROM DM_MASTERMODELXML_REF WHERE TESTCASE_GEN_STATUS LIKE 'COMPLETED' AND JELLYCASE_GEN_STATUS IS NULL ORDER BY GID"); while (rs_master.next()) { Master_ModelList.put(rs_master.getInt("GID"), rs_master.getString("FEATURENAME")); } rs_master = null; Master_statement = null; // connection.close(); } catch (SQLException e) { log.error("Error in getting data from DM_MASTERMODELXML_REF table to generate Jelly and ALM TESTS"); } catch (ClassNotFoundException e) { log.error("Exception in exemapping model function" + e.getMessage()); } if (Master_ModelList.isEmpty()) { log.info( "********************************************************************************************************************************************"); log.info( "Jelly Testcases are already generated for all the Models; Please check the column status \"JELLYCASE_GEN_STATUS\" in \"DM_MASTERMODELXML_REF\""); log.info( "********************************************************************************************************************************************"); throw new RuntimeException("Runtime Exception"); // System.exit(0); } for (int key : Master_ModelList.keySet()) { GenerateJellyTests.CreateJellyTestsFolder(Jelly_Tests_location, clean_files, Master_ModelList.get(key)); temp_jelly_Tests_location = Jelly_Tests_location + Master_ModelList.get(key); glb_Feature_Name = Master_ModelList.get(key); log.info("Started generating Jelly Tests for the Feature::" + glb_Feature_Name); log.info("***************************************************"); genjellyTests(String.valueOf(key), Master_ModelList.get(key)); try { DatabaseUtils.UpdateSingleValue("DM_MASTERMODELXML_REF", "COMPLETED", "JELLYCASE_GEN_STATUS", "GID", String.valueOf(key)); } catch (ClassNotFoundException e) { log.error("Exception in updating DM_MASTERMODELXML_REF table" + e.getMessage()); } log.info("End of generating Jelly Tests for the Feature::" + glb_Feature_Name); } }
From source file:com.sql.SystemError.java
/** * Gathers a list of errors based on type and count total of them * * @return//from w ww. j a v a 2 s. c o m */ public static List<SystemErrorModel> getErrorCounts() { List<SystemErrorModel> list = new ArrayList(); Connection conn = null; PreparedStatement ps = null; ResultSet rs = null; try { conn = DBConnection.connectToDB(); String sql = "SELECT exceptionType, COUNT(*) AS 'num' " + "FROM SystemError " + "WHERE timeOccurred >= CAST(CURRENT_TIMESTAMP AS DATE) " + "AND username != 'andrew.schmidt' " + "AND username != 'anthony.perk' " + "GROUP BY exceptionType"; ps = conn.prepareStatement(sql); rs = ps.executeQuery(); while (rs.next()) { SystemErrorModel item = new SystemErrorModel(); item.setExceptionType(rs.getString("exceptionType") == null ? "" : rs.getString("exceptionType")); item.setNumber(rs.getInt("num")); list.add(item); } } catch (SQLException ex) { ExceptionHandler.Handle(ex); } finally { DbUtils.closeQuietly(conn); DbUtils.closeQuietly(ps); DbUtils.closeQuietly(rs); } return list; }
From source file:com.act.lcms.db.model.Plate.java
protected static List<Plate> platesFromResultSet(ResultSet resultSet) throws SQLException { List<Plate> results = new ArrayList<>(); while (resultSet.next()) { Integer id = resultSet.getInt(DB_FIELD.ID.getOffset()); String name = resultSet.getString(DB_FIELD.NAME.getOffset()); String description = resultSet.getString(DB_FIELD.DESCRIPTION.getOffset()); String barcode = resultSet.getString(DB_FIELD.BARCODE.getOffset()); String location = resultSet.getString(DB_FIELD.LOCATION.getOffset()); String plateType = resultSet.getString(DB_FIELD.PLATE_TYPE.getOffset()); String solvent = resultSet.getString(DB_FIELD.SOLVENT.getOffset()); Integer temperature = resultSet.getInt(DB_FIELD.TEMPERATURE.getOffset()); if (resultSet.wasNull()) { temperature = null;/*from w w w . ja v a2s. c o m*/ } CONTENT_TYPE contentType = CONTENT_TYPE.valueOf(resultSet.getString(DB_FIELD.CONTENT_TYPE.getOffset())); results.add(new Plate(id, name, description, barcode, location, plateType, solvent, temperature, contentType)); } return results; }
From source file:com.trackplus.ddl.DataReader.java
private static int getBlobTableData(BufferedWriter writer, Connection connection) throws DDLException { try {// w w w . j a v a 2 s . co m Statement st = connection.createStatement(); ResultSet rs = st.executeQuery("SELECT * FROM TBLOB"); int idx = 0; while (rs.next()) { StringBuilder line = new StringBuilder(); //OBJECTID String value = rs.getString("OBJECTID"); line.append(value).append(","); //BLOBVALUE Blob blobValue = rs.getBlob("BLOBVALUE"); if (blobValue != null) { String str = new String(Base64.encodeBase64(blobValue.getBytes(1l, (int) blobValue.length()))); if (str.length() == 0) { str = " "; } line.append(str); } else { line.append("null"); } line.append(","); //TPUUID value = rs.getString("TPUUID"); line.append(value); writer.write(line.toString()); writer.newLine(); idx++; } rs.close(); return idx; } catch (SQLException ex) { throw new DDLException(ex.getMessage(), ex); } catch (IOException ex) { throw new DDLException(ex.getMessage(), ex); } }
From source file:com.oracle.tutorial.jdbc.StoredProcedureJavaDBSample.java
public static void getSupplierOfCoffee(String coffeeName, String[] supplierName) throws SQLException { Connection con = DriverManager.getConnection("jdbc:default:connection"); PreparedStatement pstmt = null; ResultSet rs = null; String query = "select SUPPLIERS.SUP_NAME " + "from SUPPLIERS, COFFEES " + "where SUPPLIERS.SUP_ID = COFFEES.SUP_ID " + "and ? = COFFEES.COF_NAME"; pstmt = con.prepareStatement(query); pstmt.setString(1, coffeeName);//from ww w.java 2 s . c o m rs = pstmt.executeQuery(); if (rs.next()) { supplierName[0] = rs.getString(1); } else { supplierName[0] = null; } }