Advertisement
Guest User

Untitled

a guest
Apr 11th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. import java.nio.file.Files;
  2. import java.nio.file.Paths;
  3. import java.sql.*;
  4. import java.util.ArrayList;
  5. import java.util.List;
  6. import java.util.Scanner;
  7.  
  8.  
  9. public class Cursor{
  10.  
  11.  
  12. @SuppressWarnings("unused")
  13. public static void main (String [] args) throws SQLException {
  14. Scanner teclado = new Scanner(System.in);
  15. int opcion=0, presupuesto,coddept, opcionDos=0, nuevoCodigo;
  16. String nombre, ciudad, cadena;
  17. String consulta = "select * from emple";
  18. List datos = new ArrayList();
  19. Connection conn;
  20. try {
  21. conn = leerConfig();
  22. Statement s = conn.createStatement();
  23. ResultSet rs = s.executeQuery(consulta);
  24. while(rs.next()) {
  25. System.out.println(rs.getInt("EMPNO") + "\t" + rs.getString("APELLIDO") + "\t" + rs.getString("OFICIO") + "\t" +
  26. rs.getInt("DIR") + "\t" + rs.getString("FECHAALT") + "\t" + rs.getInt("SALARIO") + "\t" + rs.getInt("COMISION") + "\t" +rs.getInt("DEPTNO") );
  27. }
  28.  
  29. }catch (Exception e){
  30. System.out.println(e);
  31. }
  32. }
  33. private static Connection leerConfig() {
  34. List<String> lineas = new ArrayList<String>();
  35. String dbName, connectionURL;
  36. Connection conn = null;
  37. try {
  38. lineas = Files.readAllLines(Paths.get("config.txt"));
  39. } catch (Exception e) {
  40. e.printStackTrace();
  41. }
  42. dbName ="@" + lineas.get(0)+ ":" + lineas.get(1) +":" + lineas.get(2);
  43. connectionURL = "jdbc:oracle:thin:" + dbName;
  44. try {
  45. DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
  46. //database connect
  47. conn = DriverManager.getConnection(connectionURL , lineas.get(3),lineas.get(4));
  48. System.out.println("Conectado");
  49. }catch(Exception e){
  50. System.out.println("Opcion no valida");
  51. }
  52. return conn;
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement