Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package br.com.jdbc;
- import java.sql.*;
- public class ConectaBanco {
- public static void main(String [] args) {
- try {
- Class.forName("oracle.jdbc.driver.OracleDriver");
- Connection con = DriverManager.getConnection("jdbc:oracle:thin:user/pass@host:1522/base");
- Statement stmt = con.createStatement();
- String sql ="Select * from acesso where nrdocumento ='999999999999'";
- ResultSet res = stmt.executeQuery(sql);
- while (res.next()); {
- String hash = res.getString(3);
- System.out.println(hash);
- }
- con.close();
- } catch (Exception e ) {
- e.printStackTrace();
- }
- }
- }
- finally {
- if(stmt != null) {
- stmt.close();
- }
- if(rs != null) {
- rs.close();
- }
- if(con != null) {
- con.close();
- }
- }
- stmt = con.createStatement();
- sql = " SUA SEGUNDA QUERY COM HASH = '" + hash + "' ";
- rs = stmt.executeQuery(sql);
- while (rs.next()) {
- //leitura do resultado
- }
- public static void main(String [] args) {
- Connection con = null;
- ResultSet rs = null;
- Statement stmt = null;
- try {
- String sql = "";
- String hash = "";
- Class.forName("oracle.jdbc.driver.OracleDriver");
- Connection con = DriverManager.getConnection("jdbc:oracle:thin:user/pass@host:1522/base");
- stmt = con.createStatement();
- sql = " Select * from acesso where nrdocumento ='999999999999' ";
- rs = stmt.executeQuery(sql);
- while (rs.next()) {
- hash = rs.getString(3);
- }
- rs.close();
- stmt = con.createStatement(); //não tenho certeza se precisa chamar novamente
- sql = " SUA SEGUNDA QUERY COM HASH = '" + hash + "' ";
- rs = stmt.executeQuery(sql);
- while (rs.next()) {
- //leitura do resultado
- }
- } catch (SQLException e ) {
- e.printStackTrace();
- } finally {
- if(stmt != null) {
- stmt.close();
- }
- if(rs != null) {
- rs.close();
- }
- if(con != null) {
- con.close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement