Advertisement
joaopedrobc

Untitled

Sep 5th, 2014
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.98 KB | None | 0 0
  1.  
  2. import java.sql.Connection;
  3. import java.sql.DriverManager;
  4. import java.sql.SQLException;
  5. import java.sql.Statement;
  6.  
  7. public class TBLogs{
  8.    
  9.     public Connection connection;
  10.  
  11.     public TBLogs(){
  12.         this.connecton = DBConnection.getConnection();
  13.     }
  14.  
  15.     public void initTB() {
  16.         try {
  17.             // Remove e cria a tabela a cada execuรงรฃo. Mero exemplo
  18.             Statement stm = this.connection.createStatement();
  19.             stm.executeUpdate("DROP TABLE IF EXISTS logs");
  20.             stm.executeUpdate("CREATE TABLE logs ("
  21.                     + "id INTEGER PRIMARY KEY   AUTOINCREMENT,"
  22.                     + "operation    TEXT      NOT NULL,"
  23.                     + "timestamp BLOB    NOT NULL,"
  24.                     + "details TEXT);");
  25.         } catch (SQLException e) {
  26.             e.printStackTrace();
  27.         }
  28.     }
  29.  
  30.     public void insert() {
  31.         try {
  32.             Statement stm = this.connection.createStatement();
  33.             String sql = "INSERT INTO logs(operation,timestamp,details) VALUES ('teste', 1,'teste2');";
  34.             stm.executeUpdate(sql);
  35.         } catch (SQLException e) {
  36.             e.printStackTrace();
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement