SHARE
TWEET

Untitled

a guest Sep 3rd, 2018 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. private Connection con = null; //variavel para conexao
  2. private Statement statement;
  3. private ResultSet resultSet;
  4.     //jdbc:firebirdsql:127.0.0.1/3050:java/
  5. private final String databaseURL = "jdbc:firebirdsql:Localhost:C:/BLVendasFirebird/firebird/sisvenda.fdb";
  6. private final String user = "SYSDBA";
  7. private final String password = "masterkey";
  8. private final String driverName = "org.localhost.firebirdsql.jdbc.FBDriver";
  9.  
  10. /**
  11.  * Abre uma conexao com o banco
  12.  */
  13. public void conectar() {
  14.     try {
  15.         Class.forName(driverName).newInstance();
  16.         this.con = DriverManager.getConnection(databaseURL, user, password);
  17.         System.out.println("Conexão obtida com sucesso.");
  18.     } catch (SQLException ex) {
  19.         System.out.println("SQLException: " + ex.getMessage());
  20.         System.out.println("SQLState: " + ex.getSQLState());
  21.         System.out.println("VendorError: " + ex.getErrorCode());
  22.     } catch (Exception e) {
  23.         System.out.println("Problemas ao tentar conectar com o banco de dados: " + e);
  24.     }
  25.  
  26. }
  27.  
  28. public void executarSQL(String sql) {
  29.     try {
  30.         this.statement = con.createStatement(
  31.                 ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
  32.         this.resultSet = this.statement.executeQuery(sql);
  33.    
  34. public void executarUpdateSQL(String sql) {
  35.     try {
  36.         this.statement = con.createStatement(
  37.                 ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
  38.         this.statement.executeUpdate(sql);
  39.    
  40. /**
  41.  * Executa insert SQL
  42.  *
  43.    
  44. while (this.getResultSet().next()) {
  45.             idRetorno = this.getResultSet().getInt(1);
  46.         }
  47.  
  48.     } catch (SQLException sqlex) {
  49.         sqlex.printStackTrace();
  50.     }
  51.     return idRetorno;
  52. }
  53.  
  54. /**
  55.  * encerra a conexão corrente
  56.  *
  57.    
  58. /**
  59.  * @return the statement
  60.  */
  61. public Statement getStatement() {
  62.     return statement;
  63. }
  64.  
  65. /**
  66.  * @return the resultSet
  67.  */
  68. public ResultSet getResultSet() {
  69.     return resultSet;
  70. }
  71.  
  72. /**
  73.  * @return the con
  74.  */
  75. public Connection getCon() {
  76.     return con;
  77. }
  78.  
  79. /**
  80.  * @param con the con to set
  81.  */
  82. public void setCon(Connection con) {
  83.     this.con = con;
  84. }
  85.  
  86. /**
  87.  * @param statement the statement to set
  88.  */
  89. public void setStatement(Statement statement) {
  90.     this.statement = statement;
  91. }
  92.  
  93. /**
  94.  * @param resultSet the resultSet to set
  95.  */
  96. public void setResultSet(ResultSet resultSet) {
  97.     this.resultSet = resultSet;
  98. }
  99.    
  100. conexão mysql
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top