Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private Connection con = null; //variavel para conexao
- private Statement statement;
- private ResultSet resultSet;
- //jdbc:firebirdsql:127.0.0.1/3050:java/
- private final String databaseURL = "jdbc:firebirdsql:Localhost:C:/BLVendasFirebird/firebird/sisvenda.fdb";
- private final String user = "SYSDBA";
- private final String password = "masterkey";
- private final String driverName = "org.localhost.firebirdsql.jdbc.FBDriver";
- /**
- * Abre uma conexao com o banco
- */
- public void conectar() {
- try {
- Class.forName(driverName).newInstance();
- this.con = DriverManager.getConnection(databaseURL, user, password);
- System.out.println("Conexão obtida com sucesso.");
- } catch (SQLException ex) {
- System.out.println("SQLException: " + ex.getMessage());
- System.out.println("SQLState: " + ex.getSQLState());
- System.out.println("VendorError: " + ex.getErrorCode());
- } catch (Exception e) {
- System.out.println("Problemas ao tentar conectar com o banco de dados: " + e);
- }
- }
- public void executarSQL(String sql) {
- try {
- this.statement = con.createStatement(
- ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
- this.resultSet = this.statement.executeQuery(sql);
- public void executarUpdateSQL(String sql) {
- try {
- this.statement = con.createStatement(
- ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
- this.statement.executeUpdate(sql);
- /**
- * Executa insert SQL
- *
- while (this.getResultSet().next()) {
- idRetorno = this.getResultSet().getInt(1);
- }
- } catch (SQLException sqlex) {
- sqlex.printStackTrace();
- }
- return idRetorno;
- }
- /**
- * encerra a conexão corrente
- *
- /**
- * @return the statement
- */
- public Statement getStatement() {
- return statement;
- }
- /**
- * @return the resultSet
- */
- public ResultSet getResultSet() {
- return resultSet;
- }
- /**
- * @return the con
- */
- public Connection getCon() {
- return con;
- }
- /**
- * @param con the con to set
- */
- public void setCon(Connection con) {
- this.con = con;
- }
- /**
- * @param statement the statement to set
- */
- public void setStatement(Statement statement) {
- this.statement = statement;
- }
- /**
- * @param resultSet the resultSet to set
- */
- public void setResultSet(ResultSet resultSet) {
- this.resultSet = resultSet;
- }
- conexão mysql
Add Comment
Please, Sign In to add comment