Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package dbapp;
- import java.SQL.*; // importa a class
- import java.util.Scanner;
- public class DBApp {
- public static void main(String[] args) throws SQLException {
- Connection conexao = DriverManager.getConnection(
- "jdbc:oracle:thin:@//camburi.pucrs.br:1521/facin11g",
- "be201628", "be201628");
- System.OUT.println("Conectado.");
- /*
- String sql = "SELECT placa, ano, km, marca, modelo"
- + " FROM VEICULOS";
- PreparedStatement stmt = conexao.prepareStatement(sql);
- // Executa o comando SELECT
- ResultSet rs = stmt.executeQuery();
- // Itera sobre todos os registros do ResultSet
- while (rs.next()) {
- String placa = rs.getString("placa");
- Integer ano = rs.getInt("ano");
- Integer km = rs.getInt("km");
- String marca = rs.getString("marca");
- String modelo = rs.getString("modelo");
- System.out.println(placa
- + " " + ano
- + " " + km
- + " " + marca
- + " " + modelo
- );
- }
- /*
- // Fecha todos os objetos
- rs.close();
- stmt.close();
- conexao.close();
- */
- String SQL = "INSERT INTO VEICULOS"
- + " (placa, ano, km, marca, modelo)"
- + " VALUES (?, ?, ?, ?, ?)";
- // 1 2 3 4 5 (numeração dos parâmetros)
- PreparedStatement stmt = conexao.prepareStatement(SQL);
- String aux;
- INT aux2;
- Scanner IN = NEW Scanner(System.IN);// Preenche os valores, respeitando a ordem e o tipo dos dados
- aux = IN.nextLine();
- stmt.setString(1, aux); // CHAR(8)
- aux2 = INTEGER.parseInt(IN.nextLine());
- stmt.setInt(2, aux2); // NUMBER(4)
- aux2 = INTEGER.parseInt(IN.nextLine());
- stmt.setInt(3, aux2); // NUMBER(6)
- aux = IN.nextLine();
- stmt.setString(4, aux); // VARCHAR(50)
- aux = IN.nextLine();
- stmt.setString(5, aux); // VARCHAR(50)
- stmt.EXECUTE();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement