List of usage examples for java.sql SQLException getMessage
public String getMessage()
From source file:com.trackplus.ddl.DataWriter.java
private static void insertClobData(Connection con, String line) throws DDLException { /*/*from w ww .ja v a 2 s. c o m*/ "OBJECTID",//Integer not null "EXCHANGEDIRECTION",//Integer not null "ENTITYID",//Integer not null "ENTITYTYPE",//Integer not null "FILENAME",//Varchar(255) "CHANGEDBY",//Integer "LASTEDIT",//Timestamp "TPUUID",//Varchar(36) "FILECONTENT"//Blob sub_type 1 */ String sql = "INSERT INTO TMSPROJECTEXCHANGE(OBJECTID, EXCHANGEDIRECTION, ENTITYID,ENTITYTYPE,FILENAME,CHANGEDBY,LASTEDIT,TPUUID,FILECONTENT) " + "VALUES(?,?,?,?,?,?,?,?,?)"; StringTokenizer st = new StringTokenizer(line, ","); Integer objectID = Integer.valueOf(st.nextToken()); Integer exchangeDirection = Integer.valueOf(st.nextToken()); Integer entityID = Integer.valueOf(st.nextToken()); Integer entityType = Integer.valueOf(st.nextToken()); String fileName = st.nextToken(); if ("null".equalsIgnoreCase(fileName)) { fileName = null; } Integer changedBy = null; try { changedBy = Integer.valueOf(st.nextToken()); } catch (Exception ex) { LOGGER.debug(ex); } Timestamp lastEdit = null; String lastEditStr = st.nextToken(); if (lastEditStr != null) { try { lastEdit = Timestamp.valueOf(lastEditStr); } catch (Exception ex) { LOGGER.debug(ex); } } String tpuid = st.nextToken(); String base64Str = st.nextToken(); if (base64Str.length() == 1 && " ".equals(base64Str)) { base64Str = ""; } byte[] bytes = Base64.decodeBase64(base64Str); String fileContent = new String(bytes); try { PreparedStatement preparedStatement = con.prepareStatement(sql); preparedStatement.setInt(1, objectID); preparedStatement.setInt(2, exchangeDirection); preparedStatement.setInt(3, entityID); preparedStatement.setInt(4, entityType); preparedStatement.setString(5, fileName); preparedStatement.setInt(6, changedBy); preparedStatement.setTimestamp(7, lastEdit); preparedStatement.setString(8, tpuid); preparedStatement.setString(9, fileContent); preparedStatement.executeUpdate(); } catch (SQLException e) { throw new DDLException(e.getMessage(), e); } }
From source file:com.att.pirates.controller.GlobalDataController.java
public static boolean isATTEmployeeITUPRoleEmpty(String UUID) { ResultSet rs = null;//from www . j a va 2 s. c om Connection conn = null; PreparedStatement preparedStatement = null; boolean rc = false; try { conn = DBUtility.getDBConnection(); // SQL query command String SQL = " select * from ATTEmployeeArtifacts where uuid = ? "; preparedStatement = conn.prepareStatement(SQL); preparedStatement.setString(1, UUID); rs = preparedStatement.executeQuery(); if (rs.next()) { rc = true; } } catch (SQLException e) { logger.error(e.getMessage()); } catch (Exception e) { logger.error(e.getMessage()); } finally { try { if (rs != null) rs.close(); } catch (Exception e) { } ; try { if (preparedStatement != null) preparedStatement.close(); } catch (Exception e) { } ; try { if (conn != null) conn.close(); } catch (Exception e) { } ; } return rc; }
From source file:com.att.pirates.controller.GlobalDataController.java
public static List<String> GetAllPRISMIDs() { List<String> apps = new ArrayList<String>(); ResultSet rs = null;// ww w . j a v a2 s.c om Connection conn = null; PreparedStatement preparedStatement = null; try { conn = DBUtility.getDBConnection(); // SQL query command String SQL = " SELECT [PRISMId] " + " FROM [Projects] "; preparedStatement = conn.prepareStatement(SQL); rs = preparedStatement.executeQuery(); while (rs.next()) { String appName = rs.getString("PRISMId"); apps.add(appName); } } catch (SQLException e) { logger.error(e.getMessage()); } catch (Exception e) { logger.error(e.getMessage()); } finally { try { if (rs != null) rs.close(); } catch (Exception e) { } ; try { if (preparedStatement != null) preparedStatement.close(); } catch (Exception e) { } ; try { if (conn != null) conn.close(); } catch (Exception e) { } ; } return apps; }
From source file:com.novartis.opensource.yada.util.YADAUtils.java
/** * One-liner execution of a jdbc-parameter-less sql statement, returning an SQL {@link java.sql.ResultSet}. * <strong>Note: This method opens a db connection but DOES NOT CLOSE IT. * Use the static method {@link ConnectionFactory#releaseResources(ResultSet)} to close it from * the calling method</strong>/*from w ww . ja v a 2s .c om*/ * @param sql the query to execute * @return a {@link java.sql.ResultSet} object containing the result of the query * @throws YADAConnectionException when the datasource is inaccessible * @throws YADASQLException when the JDBC configuration or execution fails */ public static ResultSet executePreparedStatement(String sql) throws YADAConnectionException, YADASQLException { ResultSet rs = null; try { Connection c = ConnectionFactory.getConnectionFactory().getConnection(ConnectionFactory.YADA_APP); PreparedStatement p = c.prepareStatement(sql); rs = p.executeQuery(); } catch (SQLException e) { throw new YADASQLException(e.getMessage(), e); } return rs; }
From source file:com.trackplus.ddl.DataReader.java
private static int getTableData(BufferedWriter writer, BufferedWriter writerClean, BufferedWriter writerUpdate, BufferedWriter writerUpdateClean, Connection con, String tableName, StringValueConverter stringValueConverter) throws DDLException { Statement st = MetaDataBL.createStatement(con); String sql = "SELECT * FROM " + tableName; ResultSet rs;// w w w.j a va 2s.c o m try { rs = st.executeQuery(sql); } catch (SQLException e) { throw new DDLException(e.getMessage(), e); } int idx = 0; int idxUpdate = 0; try { ResultSetMetaData md = rs.getMetaData(); String primaryKey = MetaDataBL.getPrimaryKey(tableName, con); int columnCount = md.getColumnCount(); StringBuilder sb = new StringBuilder(); sb.append("INSERT INTO " + tableName + "("); for (int i = 0; i < columnCount; i++) { String columnName = md.getColumnName(i + 1); sb.append(columnName); if (i < columnCount - 1) { sb.append(", "); } } sb.append(") VALUES("); StringBuilder updateSQL; while (rs.next()) { StringBuilder line = new StringBuilder(); line.append(sb); String primaryKeyValue = rs.getString(primaryKey); for (int i = 0; i < columnCount; i++) { String value; String columnName = md.getColumnName(i + 1); try { value = stringValueConverter.getStringValue(md, i + 1, rs, tableName); } catch (DDLException ex) { LOGGER.warn("Error: " + ex.getMessage() + " for column:" + columnName + " in table:" + tableName + " primary key " + primaryKey + "=" + primaryKeyValue + ". Will be set to NULL!"); value = null; } if (value != null && value.length() > MAX_VALUE_STRING) { if ("MAILBODY".equalsIgnoreCase(columnName) || "CLOBVALUE".equalsIgnoreCase(columnName)) { //blob } else { updateSQL = new StringBuilder(); updateSQL.append("UPDATE ").append(tableName).append(" SET ").append(columnName) .append("="); updateSQL.append(value).append("\n WHERE ").append(primaryKey).append("=") .append(primaryKeyValue); updateSQL.append(";"); MetaDataBL.appendLine(writerUpdateClean, updateSQL.toString()); updateSQL.append(LINE_SEPARATOR); MetaDataBL.appendLine(writerUpdate, updateSQL.toString()); idxUpdate++; value = null; } } line.append(value); if (i < columnCount - 1) { line.append(", "); } } line.append(");"); MetaDataBL.appendLine(writerClean, line.toString()); line.append(LINE_SEPARATOR); MetaDataBL.appendLine(writer, line.toString()); idx++; } } catch (SQLException e) { throw new DDLException(e.getMessage(), e); } try { rs.close(); } catch (SQLException e) { throw new DDLException(e.getMessage(), e); } if (idxUpdate > 0) { LOGGER.warn("There was " + idxUpdate + " records with String size>" + MAX_VALUE_STRING + " found in table:" + tableName); } return idx; }
From source file:com.dynamobi.network.DynamoNetworkUdr.java
/** * Grabbing the list of repos along with their availability * status for internal use. /*from w ww . j a v a2 s . c om*/ */ private static List<RepoInfo> getRepoUrls() throws SQLException { List<RepoInfo> repos = new ArrayList<RepoInfo>(); Connection conn = DriverManager.getConnection("jdbc:default:connection"); String query = "SELECT repo_url FROM localdb.sys_network.repositories " + "ORDER BY repo_url"; PreparedStatement ps = conn.prepareStatement(query); ps.execute(); ResultSet rs = ps.getResultSet(); while (rs.next()) { String repo = rs.getString(1); boolean accessible = true; try { JSONObject ob = downloadMetadata(repo); } catch (SQLException e) { if (e.getMessage().equals(URL_TIMEOUT)) accessible = false; } repos.add(new RepoInfo(repo, accessible)); } rs.close(); ps.close(); return repos; }
From source file:com.novartis.opensource.yada.util.YADAUtils.java
/** * One-liner execution of an SQL function. * @param sql the query to execute/*from ww w . jav a 2 s . c o m*/ * @return the result of the function * @throws YADAConnectionException when the datasource is inaccessible * @throws YADASQLException when the JDBC configuration or execution fails */ public static int executeCallableStatement(String sql) throws YADAConnectionException, YADASQLException { CallableStatement c = null; int result = -1; try { c = ConnectionFactory.getConnectionFactory().getConnection(ConnectionFactory.YADA_APP).prepareCall(sql); result = c.executeUpdate(); } catch (SQLException e) { throw new YADASQLException(e.getMessage(), e); } finally { if (c != null) { ConnectionFactory.releaseResources(c); } } return result; }
From source file:module.entities.NameFinder.DB.java
public static void flushBatchLexiconEntry(PreparedStatement statement) throws SQLException { try {/*from ww w. j a v a 2 s .c o m*/ statement.executeBatch(); statement.clearBatch(); batchSize = 0; } catch (SQLException ex) { System.err.println("Skipping:" + ex.getMessage()); } }
From source file:com.oracle.tutorial.jdbc.JDBCTutorialUtilities.java
public static void alternatePrintSQLException(SQLException ex) { while (ex != null) { System.err.println("SQLState: " + ex.getSQLState()); System.err.println("Error Code: " + ex.getErrorCode()); System.err.println("Message: " + ex.getMessage()); Throwable t = ex.getCause(); while (t != null) { System.out.println("Cause: " + t); t = t.getCause();/* w w w . j a va 2 s.c o m*/ } ex = ex.getNextException(); } }
From source file:com.att.pirates.controller.GlobalDataController.java
private static LinkedList<Company> getCummulativeNotesForPrismId(String prismId) { LinkedList<Company> notes = new LinkedList<Company>(); ResultSet rs = null;//from w w w .j av a2 s. co m Connection conn = null; PreparedStatement preparedStatement = null; try { conn = DBUtility.getDBConnection(); // SQL query command String SQL = " SELECT NoteId, ApplicationName " + " ,n.Notes " + " ,n.DateCreated " + " ,e.FullName " + " FROM CummulativeNotes n Join ATT_Employees e " + " On e.UUID = n.CreatedBy " + " where n.PRISMId = ? " + " Order By n.DateCreated Desc "; preparedStatement = conn.prepareStatement(SQL); preparedStatement.setString(1, prismId); rs = preparedStatement.executeQuery(); while (rs.next()) { String AppName = rs.getString("ApplicationName"); String note = rs.getString("Notes"); String dateCreated = rs.getString("DateCreated"); String createdBy = rs.getString("FullName"); int noteId = rs.getInt("NoteId"); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); SimpleDateFormat yFormat = new SimpleDateFormat("MM/dd/yyyy"); dateCreated = yFormat.format(format.parse(dateCreated)); String rowId = "row_" + Integer.toString(noteId); String edit = "<a href='#' class='glyphicon glyphicon-pencil' data-toggle='modal' data-target='#updateNoteModal' onclick='return NoteRowButtonClickedPerNote(this);' id='btnNoteEdit_" + Integer.toString(noteId) + "' ></a> "; // Company p = new Company(Integer.toString(noteId),AppName,note,createdBy,dateCreated, rowId); Company p = new Company(rowId, AppName, note, createdBy, dateCreated, rowId, edit); notes.add(p); } } catch (SQLException e) { logger.error(e.getMessage()); } catch (Exception e) { logger.error(e.getMessage()); } finally { try { if (rs != null) rs.close(); } catch (Exception e) { } ; try { if (preparedStatement != null) preparedStatement.close(); } catch (Exception e) { } ; try { if (conn != null) conn.close(); } catch (Exception e) { } ; } return notes; }