java.sql.SQLException.getMessage()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(9.1k)|赞(0)|评价(0)|浏览(208)

本文整理了Java中java.sql.SQLException.getMessage()方法的一些代码示例,展示了SQLException.getMessage()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。SQLException.getMessage()方法的具体详情如下:
包路径:java.sql.SQLException
类名称:SQLException
方法名:getMessage

SQLException.getMessage介绍

暂无

代码示例

代码示例来源:origin: alibaba/canal

@Override
  public void close() {
    if (conn != null) {
      try {
        conn.close();
      } catch (SQLException e) {
        logger.error(e.getMessage(), e);
      } finally {
        conn = null;
      }
    }
  }
}

代码示例来源:origin: elasticjob/elastic-job-lite

private String getOriginalTaskId(final String taskId) {
  String sql = String.format("SELECT original_task_id FROM %s WHERE task_id = '%s' and state='%s' LIMIT 1", TABLE_JOB_STATUS_TRACE_LOG, taskId, State.TASK_STAGING);
  String result = "";
  try (
      Connection conn = dataSource.getConnection();
      PreparedStatement preparedStatement = conn.prepareStatement(sql);
      ResultSet resultSet = preparedStatement.executeQuery()
  ) {
    if (resultSet.next()) {
      return resultSet.getString("original_task_id");
    }
  } catch (final SQLException ex) {
    // TODO 记录失败直接输出日志,未来可考虑配置化
    log.error(ex.getMessage());
  }
  return result;
}

代码示例来源:origin: iluwatar/java-design-patterns

/**
  * {@inheritDoc}
  */
 @Override
 public boolean delete(Customer customer) throws Exception {
  try (Connection connection = getConnection();
    PreparedStatement statement = 
      connection.prepareStatement("DELETE FROM CUSTOMERS WHERE ID = ?")) {
   statement.setInt(1, customer.getId());
   return statement.executeUpdate() > 0;
  } catch (SQLException ex) {
   throw new CustomException(ex.getMessage(), ex);
  }
 }
}

代码示例来源:origin: iluwatar/java-design-patterns

/**
 * {@inheritDoc}
 */
@Override
public boolean update(Customer customer) throws Exception {
 try (Connection connection = getConnection();
   PreparedStatement statement = 
     connection.prepareStatement("UPDATE CUSTOMERS SET FNAME = ?, LNAME = ? WHERE ID = ?")) {
  statement.setString(1, customer.getFirstName());
  statement.setString(2, customer.getLastName());
  statement.setInt(3, customer.getId());
  return statement.executeUpdate() > 0;
 } catch (SQLException ex) {
  throw new CustomException(ex.getMessage(), ex);
 }
}

代码示例来源:origin: igniterealtime/Openfire

private static void loadAssociatedGroups(Map<String, Node> nodes, ResultSet rs) {
  try {
    String nodeID = decodeNodeID(rs.getString(1));
    Node node = nodes.get(nodeID);
    if (node == null) {
      log.warn("Roster Group associated to a non-existent node: " + nodeID);
      return;
    }
    node.addAllowedRosterGroup(rs.getString(2));
  }
  catch (SQLException ex) {
    log.error(ex.getMessage(), ex);
  }
}

代码示例来源:origin: alibaba/canal

Util.sqlRS(conn, sql, rs -> {
    try {
      if (rs.next()) {
        Long rowCount = rs.getLong("cnt");
        res.put("count", rowCount);
      logger.error(e.getMessage(), e);
  logger.error(e.getMessage(), e);
} finally {
  if (conn != null) {
      conn.close();
    } catch (SQLException e) {
      logger.error(e.getMessage(), e);

代码示例来源:origin: igniterealtime/Openfire

@Override
public void destroy() {
  // Shutdown the database.
  Connection con = null;
  PreparedStatement pstmt = null;
  try {
    con = getConnection();
    pstmt = con.prepareStatement("SHUTDOWN");
    pstmt.execute();
  }
  catch (SQLException sqle) {
    Log.error(sqle.getMessage(), sqle);
  }
  finally {
    DbConnectionManager.closeConnection(pstmt, con);
  }
}

代码示例来源:origin: hibernate/hibernate-orm

@Override
  public Connection getConnection() throws SQLException {
    Connection connection = super.getConnection();
    try(Statement statement = connection.createStatement()) {
      if ( dbName == null ) {
        try(ResultSet rs = statement.executeQuery( "SELECT DB_NAME()" )) {
          rs.next();
          dbName = rs.getString( 1 );
        }
      }
      statement.executeUpdate(String.format( RCS, dbName, "ON" ));
      statement.executeUpdate(String.format( SI, dbName, "ON" ));
    }
    catch (SQLException se) {
      fail( se.getMessage());
    }
    return connection;
  }
}

代码示例来源:origin: apache/flink

Object param = parameterValues[inputSplit.getSplitNumber()][i];
      if (param instanceof String) {
        statement.setString(i + 1, (String) param);
      } else if (param instanceof Long) {
        statement.setLong(i + 1, (Long) param);
  resultSet = statement.executeQuery();
  hasNext = resultSet.next();
} catch (SQLException se) {
  throw new IllegalArgumentException("open() failed." + se.getMessage(), se);

代码示例来源:origin: iluwatar/java-design-patterns

/**
 * {@inheritDoc}
 */
@Override
public boolean add(Customer customer) throws Exception {
 if (getById(customer.getId()).isPresent()) {
  return false;
 }
 try (Connection connection = getConnection();
   PreparedStatement statement = 
     connection.prepareStatement("INSERT INTO CUSTOMERS VALUES (?,?,?)")) {
  statement.setInt(1, customer.getId());
  statement.setString(2, customer.getFirstName());
  statement.setString(3, customer.getLastName());
  statement.execute();
  return true;
 } catch (SQLException ex) {
  throw new CustomException(ex.getMessage(), ex);
 }
}

代码示例来源:origin: iluwatar/java-design-patterns

try {
 connection = getConnection();
 PreparedStatement statement = connection.prepareStatement("SELECT * FROM CUSTOMERS"); // NOSONAR
 ResultSet resultSet = statement.executeQuery(); // NOSONAR
 return StreamSupport.stream(new Spliterators.AbstractSpliterator<Customer>(Long.MAX_VALUE, 
   Spliterator.ORDERED) {
 throw new CustomException(e.getMessage(), e);

代码示例来源:origin: apache/flink

/**
 * Stores the next resultSet row in a tuple.
 *
 * @param row row to be reused.
 * @return row containing next {@link Row}
 * @throws java.io.IOException
 */
@Override
public Row nextRecord(Row row) throws IOException {
  try {
    if (!hasNext) {
      return null;
    }
    for (int pos = 0; pos < row.getArity(); pos++) {
      row.setField(pos, resultSet.getObject(pos + 1));
    }
    //update hasNext after we've read the record
    hasNext = resultSet.next();
    return row;
  } catch (SQLException se) {
    throw new IOException("Couldn't read data - " + se.getMessage(), se);
  } catch (NullPointerException npe) {
    throw new IOException("Couldn't access resultSet", npe);
  }
}

代码示例来源:origin: apache/flink

@Override
public void openInputFormat() {
  //called once per inputFormat (on open)
  try {
    Class.forName(drivername);
    if (username == null) {
      dbConn = DriverManager.getConnection(dbURL);
    } else {
      dbConn = DriverManager.getConnection(dbURL, username, password);
    }
    statement = dbConn.prepareStatement(queryTemplate, resultSetType, resultSetConcurrency);
    if (fetchSize == Integer.MIN_VALUE || fetchSize > 0) {
      statement.setFetchSize(fetchSize);
    }
  } catch (SQLException se) {
    throw new IllegalArgumentException("open() failed." + se.getMessage(), se);
  } catch (ClassNotFoundException cnfe) {
    throw new IllegalArgumentException("JDBC-Class not found. - " + cnfe.getMessage(), cnfe);
  }
}

代码示例来源:origin: iluwatar/java-design-patterns

/**
 * {@inheritDoc}
 */
@Override
public Optional<Customer> getById(int id) throws Exception {
 ResultSet resultSet = null;
 try (Connection connection = getConnection();
   PreparedStatement statement = 
     connection.prepareStatement("SELECT * FROM CUSTOMERS WHERE ID = ?")) {
  statement.setInt(1, id);
  resultSet = statement.executeQuery();
  if (resultSet.next()) {
   return Optional.of(createCustomer(resultSet));
  } else {
   return Optional.empty();
  }
 } catch (SQLException ex) {
  throw new CustomException(ex.getMessage(), ex);
 } finally {
  if (resultSet != null) {
   resultSet.close();
  }
 }
}

代码示例来源:origin: yu199195/myth

private int executeUpdate(final String sql, final Object... params) {
  try (Connection connection = dataSource.getConnection();
     PreparedStatement ps = connection.prepareStatement(sql)) {
    if (params != null) {
      for (int i = 0; i < params.length; i++) {
        ps.setObject(i + 1, params[i]);
      }
    }
    return ps.executeUpdate();
  } catch (SQLException e) {
    LOGGER.error("executeUpdate-> " + e.getMessage());
  }
  return 0;
}

代码示例来源:origin: alibaba/canal

public Connection getConn() {
  if (conn == null) {
    try {
      conn = dataSource.getConnection();
      this.conn.setAutoCommit(false);
    } catch (SQLException e) {
      logger.error(e.getMessage(), e);
    }
  }
  return conn;
}

代码示例来源:origin: spring-projects/spring-framework

tables = databaseMetaData.getTables(
    catalogNameToUse(catalogName), schemaNameToUse(schemaName), tableNameToUse(tableName), null);
while (tables != null && tables.next()) {
  TableMetaData tmd = new TableMetaData();
  tmd.setCatalogName(tables.getString("TABLE_CAT"));
  tmd.setSchemaName(tables.getString("TABLE_SCHEM"));
  tmd.setTableName(tables.getString("TABLE_NAME"));
  if (tmd.getSchemaName() == null) {
    tableMeta.put(this.userName != null ? this.userName.toUpperCase() : "", tmd);
  logger.warn("Error while accessing table meta-data results: " + ex.getMessage());

代码示例来源:origin: Netflix/conductor

public Query(ObjectMapper objectMapper, Connection connection, String query) {
  this.rawQuery = query;
  this.om = objectMapper;
  try {
    this.statement = connection.prepareStatement(query);
  } catch (SQLException ex) {
    throw new ApplicationException(Code.BACKEND_ERROR,
        "Cannot prepare statement for query: " + ex.getMessage(), ex);
  }
}

代码示例来源:origin: igniterealtime/Openfire

@Override
public Collection<String> getVisibleGroupNames(String userGroup) {
  Set<String> groupNames = new HashSet<>();
  Connection con = null;
  PreparedStatement pstmt = null;
  ResultSet rs = null;
  try {
    con = DbConnectionManager.getConnection();
    pstmt = con.prepareStatement(GROUPLIST_CONTAINERS);
    pstmt.setString(1, "%" + userGroup + "%");
    rs = pstmt.executeQuery();
    while (rs.next()) {
      groupNames.add(rs.getString(1));
    }
  }
  catch (SQLException sqle) {
    Log.error(sqle.getMessage(), sqle);
  }
  finally {
    DbConnectionManager.closeConnection(rs, pstmt, con);
  }
  return groupNames;
}

代码示例来源:origin: igniterealtime/Openfire

private void deleteProperty(String name) {
  Connection con = null;
  PreparedStatement pstmt = null;
  try {
    con = DbConnectionManager.getConnection();
    pstmt = con.prepareStatement(DELETE_PROPERTY);
    pstmt.setString(1, name + "%");
    pstmt.executeUpdate();
  }
  catch (SQLException e) {
    Log.error(e.getMessage(), e);
  }
  finally {
    DbConnectionManager.closeConnection(pstmt, con);
  }
}

相关文章