-1
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class Principal {
public static void main(String[] args) {
Connection c;
PreparedStatement ps = null;
ResultSet rs = null;
String url = "jdbc:oracle:thin:@localhost:1521: XE";
String usuario = "SYSTEM";
String senha = "BANCO_OPET";
String sql = "";
try {;
// 1º estabelecer a conexao
Class.forName("oracle.jdbc.driver.OracleDriver");
c = DriverManager.getConnection(url, usuario, senha);
System.out.println("Conectou com sucesso");
rs.close();
ps.close();
c.close();
System.out.println("Fechou a conexão");
} catch (SQLException e) {
System.out.println("Erro ao conectar: " + e.getMessage());
} catch (ClassNotFoundException e) {
System.out.println("Erro ao registrar: " + e.getMessage());
}
}
}