Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package com.mycompany.projetourb;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Scanner;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- /**
- *
- * @author Aluno
- */
- public class Main {
- public static void main(String[] args) throws ClassNotFoundException, SQLException {
- Connection con = null;
- try {
- con = DriverManager.getConnection(
- "jdbc:postgresql://127.0.0.1:5432/projeto", "postgres",
- "ALUNO");
- } catch (SQLException e) {
- System.out.println("Falha na conexão");
- e.printStackTrace();
- }
- if (con != null) {
- System.out.println("Conexão realizada com sucesso!");
- } else {
- System.out.println("Erro ao conectar");
- }
- Scanner sc = new Scanner(System.in);
- System.out.println("Digite o endereço a ser pesquisado: ");
- String pesquisa = sc.nextLine();
- String sql = "select * from ruas where nome = '" + pesquisa + "'" + " and municipio = 'Lages'";
- PreparedStatement ps = con.prepareStatement(sql);
- ResultSet rs = ps.executeQuery();
- while (rs.next()) {
- String nome = rs.getString("geom");
- System.out.println(nome);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement