List of usage examples for java.sql SQLException getMessage
public String getMessage()
From source file:net.duckling.falcon.api.boostrap.BootstrapDao.java
public boolean isTableExisted() { Connection conn = getConnection(); execute(conn, "use " + database + ";"); Statement stmt = null;//www . j ava2s.c o m ResultSet rs = null; try { stmt = conn.createStatement(); rs = stmt.executeQuery("show tables like '" + this.checkTable + "'"); return rs.next(); } catch (SQLException e) { throw new WrongSQLException(e.getMessage()); } finally { try { closeAll(conn, stmt, rs); } catch (SQLException e) { throw new WrongSQLException(e.getMessage()); } } }
From source file:org.cloudfoundry.community.servicebroker.postgresql.service.PostgreSQLServiceInstanceBindingService.java
@Override public CreateServiceInstanceBindingResponse createServiceInstanceBinding( CreateServiceInstanceBindingRequest createServiceInstanceBindingRequest) throws ServiceInstanceBindingExistsException, ServiceBrokerException { String bindingId = createServiceInstanceBindingRequest.getBindingId(); String serviceInstanceId = createServiceInstanceBindingRequest.getServiceInstanceId(); String appGuid = createServiceInstanceBindingRequest.getAppGuid(); String passwd = ""; try {/* w ww. j a v a2s.c o m*/ passwd = this.role.bindRoleToDatabase(serviceInstanceId); } catch (SQLException e) { logger.error("Error while creating service instance binding '" + bindingId + "'", e); throw new ServiceBrokerException(e.getMessage()); } String dbURL = String.format("postgres://%s:%s@%s:%d/%s", serviceInstanceId, passwd, PostgreSQLDatabase.getDatabaseHost(), PostgreSQLDatabase.getDatabasePort(), serviceInstanceId); Map<String, Object> credentials = new HashMap<String, Object>(); credentials.put("uri", dbURL); return new CreateServiceInstanceAppBindingResponse().withCredentials(credentials); }
From source file:com.nextep.designer.sqlclient.ui.handlers.ExecuteQueryHandler.java
private Connection getConnectionFromInput(ISQLEditorInput<?> input) { Connection jdbcConn = null;//from w w w . j a v a 2 s .co m IConnection targetConn = null; if (input instanceof IConnectable) { final IConnectable connectable = (IConnectable) input; jdbcConn = connectable.getSqlConnection(); targetConn = connectable.getConnection(); } if (jdbcConn == null) { if (targetConn != null) { DBGMUIHelper.checkConnectionPassword(targetConn); } else { targetConn = DBGMUIHelper.getConnection(null); } // Initializing connection try { jdbcConn = CorePlugin.getConnectionService().connect(targetConn); if (input instanceof IConnectable) { ((IConnectable) input).setSqlConnection(jdbcConn); } } catch (SQLException e) { throw new ErrorException("Could not establish connection : " + e.getMessage(), e); } } return jdbcConn; }
From source file:com.wavemaker.runtime.data.util.JDBCUtils.java
public static Object runSql(String sql[], String url, String username, String password, String driverClassName, Log logger, boolean isDDL) { Connection con = getConnection(url, username, password, driverClassName); try {/*from w ww .j a va2s . c o m*/ try { con.setAutoCommit(true); } catch (SQLException ex) { throw new DataServiceRuntimeException(ex); } Statement s = con.createStatement(); try { try { for (String stmt : sql) { if (logger != null && logger.isInfoEnabled()) { logger.info("Running " + stmt); } s.execute(stmt); } if (!isDDL) { ResultSet r = s.getResultSet(); List<Object> rtn = new ArrayList<Object>(); while (r.next()) { // getting only the first col is pretty unuseful rtn.add(r.getObject(1)); } return rtn.toArray(new Object[rtn.size()]); } } catch (Exception ex) { if (logger != null && logger.isErrorEnabled()) { logger.error(ex.getMessage()); } throw ex; } } finally { try { s.close(); } catch (Exception ignore) { } } } catch (Exception ex) { if (ex instanceof RuntimeException) { throw (RuntimeException) ex; } else { throw new DataServiceRuntimeException(ex); } } finally { try { con.close(); } catch (Exception ignore) { } } return null; }
From source file:org.qucosa.camel.component.opus4.Opus4DataSource.java
public void release() { try {//from w w w . j a va 2 s. c o m if (connection != null) { connection.close(); log.debug("Closed database connection to " + dburl); } } catch (SQLException e) { log.warn("Failed to close database connection: " + e.getMessage()); } }
From source file:br.com.great.dao.TextosDAO.java
/** * * Mtodo responsvel por get os dados da VTextos no banco de dados * * @param mecanica_id int//from ww w .ja v a 2 s . c o m * @return JSONObject Dados de VTextos * @author Carleandro Noleto * @since 14/01/2015 * @version 1.0 */ public Texto getMecVTexto(int mecanica_id) { PreparedStatement pstmt = null; ResultSet rs = null; Connection conexao = criarConexao(); Texto vtexto = null; try { String sql = "SELECT * FROM `vtextos` WHERE `vtextos`.`mecsimples_id` = " + mecanica_id; pstmt = conexao.prepareStatement(sql); rs = pstmt.executeQuery(); rs.next(); vtexto = new Texto(); vtexto.setTexto_id(rs.getInt("id")); vtexto.setTexto(rs.getString("texto")); vtexto.setMecsimples_id(rs.getInt("mecanica_id")); } catch (SQLException e) { System.out.println("Erro ao listar dados de uma mecanica texto: " + e.getMessage()); } finally { fecharConexao(conexao, pstmt, rs); } return vtexto; }
From source file:it.gulch.linuxday.android.activities.TrackScheduleEventActivity.java
private void setupServices() { try {/*from w w w . j a v a2 s .co m*/ eventManager = DatabaseManagerFactory.getEventManager(this); } catch (SQLException e) { Log.e(TAG, e.getMessage(), e); } }
From source file:net.duckling.falcon.api.boostrap.BootstrapDao.java
public boolean isDatabaseExisted() { Connection conn = getConnection(); String sql = "show databases"; Statement stmt = null;// w ww . jav a 2 s . c o m ResultSet rs = null; ArrayList<String> results = new ArrayList<String>(); try { stmt = conn.createStatement(); rs = stmt.executeQuery(sql); while (rs.next()) { results.add(rs.getString(1)); } } catch (SQLException e) { throw new WrongSQLException(e.getMessage()); } finally { try { closeAll(conn, stmt, rs); } catch (SQLException e) { throw new WrongSQLException(e.getMessage()); } } return results.contains(database); }
From source file:org.castor.jpa.functional.AbstractSpringBaseTest.java
protected final void verifyPersistentBook(Book book) throws SQLException { Connection connection = null; PreparedStatement preparedStatement = null; ResultSet resultSet = null;/*from w w w . ja v a2 s . c om*/ int fetchSize = 0; long isbn = 0; String title = null; try { // Load the book from the database. connection = this.dataSource.getConnection(); preparedStatement = connection.prepareStatement("SELECT isbn, title FROM book WHERE isbn = ?"); preparedStatement.setObject(1, Long.valueOf(book.getIsbn())); resultSet = preparedStatement.executeQuery(); fetchSize = resultSet.getFetchSize(); resultSet.next(); // Get values from result set. isbn = resultSet.getLong(1); title = resultSet.getString(2); } catch (SQLException e) { fail("Could not verify book instance: " + e.getMessage()); e.printStackTrace(); } finally { // Release resources. resultSet.close(); preparedStatement.close(); connection.close(); } // Verify result. assertEquals(1, fetchSize); assertEquals(book.getIsbn(), isbn); assertEquals(book.getTitle(), title); }
From source file:com.mycompany.rubricatelefonica.DefaultUtenteDao.java
public boolean updateUtenteInfo(String nome, String email) { boolean inserito = false; MysqlDataSource dataSource = new MysqlDataSource(); dataSource.setUser("root"); dataSource.setPassword("root"); dataSource.setUrl("jdbc:mysql://localhost:3306/RubricaTelef"); Connection conn = null;/* w ww . j av a 2s. com*/ try { conn = dataSource.getConnection(); PreparedStatement stmtUpdateUtente = conn.prepareStatement(UPDATE); stmtUpdateUtente.setString(1, nome); stmtUpdateUtente.setString(2, email); if (stmtUpdateUtente.executeUpdate() > 0) { inserito = true; } } catch (SQLException e) { System.out.println(e.getMessage()); System.out.println("errore!! Connessione Fallita"); } finally { DbUtils.closeQuietly(conn); //oppure try with resource } // return inserito; }