Guest User

Untitled

a guest
Nov 4th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. public void SelectBD(String Banco)
  2. {
  3. BANCO = Banco;
  4. if (BANCO.equals("SQL"))
  5. {
  6. //CONEXAO SQL EXPRESS
  7. URL = "jdbc:jtds:sqlserver://localhost:1433/BancoSQL;";
  8. DRIVER = "net.sourceforge.jtds.jdbc.Driver";
  9. USUARIO = "sa";
  10. SENHA = "123456";
  11. }
  12. else if(BANCO.equals("ORACLE"))
  13. {
  14. //CONEXAO ORACLE EXPRESS
  15. URL = "jdbc:oracle:thin:@localhost:1521:xe";
  16. DRIVER = "oracle.jdbc.driver.OracleDriver";
  17. USUARIO = "android"; //"sys as sysdba";
  18. SENHA = "123456";
  19. }
  20. }
  21.  
  22. public Statement ponte;
  23. public String status = "";
  24. public String getStatus()
  25. {
  26. return status;
  27. }
  28.  
  29. public Conexao()
  30. {
  31. try {
  32. System.out.println("Banco "+ BANCO);
  33. SelectBD(BANCO);
  34. if (BANCO.equals("SQL"))
  35. {
  36. Class.forName(DRIVER);
  37. Connection con;
  38. con = DriverManager.getConnection(URL,USUARIO,SENHA);
  39. ponte = con.createStatement();
  40. }
  41. else if(BANCO.equals("ORACLE"))
  42. {
  43. Class.forName(DRIVER);
  44. Connection con;
  45. OracleDataSource ds;
  46. ds = new OracleDataSource();
  47. ds.setURL(URL);
  48. con = ds.getConnection(USUARIO,SENHA);
  49. ponte = con.createStatement();
  50. }
  51. status = "Conectado no banco " + BANCO + "!!!" ;
  52. } catch (Exception e) {
  53. status = e.getMessage();
  54. e.printStackTrace();
  55. }
  56. }
  57.  
  58. public void manutencao(String sql)
  59. {
  60. try {
  61. ponte.executeUpdate(sql);
  62. } catch (Exception e) {
  63. e.printStackTrace();
  64. }
  65. }
Add Comment
Please, Sign In to add comment