Example usage for java.sql SQLException printStackTrace

List of usage examples for java.sql SQLException printStackTrace

Introduction

In this page you can find the example usage for java.sql SQLException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:com.ery.hadoop.mrddx.hive.HiveOutputFormat.java

/**
 * ???/*from  w ww  .  ja v  a  2s .co  m*/
 * 
 * @param job The job
 * @param tableName The table to insert data into
 * @param fieldNames The field names in the table.
 * @param ddlHQL require execute HQL before mapreduce running
 */
public static void setOutputParameter(Configuration job, boolean compress, String compressCodec,
        String fieldSplitChars, String rowsSplitChars, String ddlHQL) {
    HiveConfiguration hiveConf = new HiveConfiguration(job);
    hiveConf.setOutputHiveCompress(compress);
    hiveConf.setOutputHiveCompressCodec(compressCodec);
    hiveConf.setOutputHiveFileFieldSplitChars(fieldSplitChars);
    hiveConf.setOutputHiveFileRowsSplitChars(rowsSplitChars);
    hiveConf.setOutputHiveExecuteDDLHQL(ddlHQL);
    try {
        executeDDLHQL(hiveConf);
        MRLog.info(LOG, "execute ddl hive sql success!");
    } catch (SQLException e) {
        MRLog.error(LOG, "execute ddl hive sql error!");
        e.printStackTrace();
    }
}

From source file:com.jaspersoft.jasperserver.api.engine.common.virtualdatasourcequery.VirtualSQLDataSource.java

public static Set<String> discoverNonEmptySchemas(Connection conn) throws SQLException {
    DatabaseMetaData dbMetaData = conn.getMetaData();
    try {/*w w w  .  ja v  a  2 s . c  om*/
        Set<String> set = new LinkedHashSet<String>();
        Set<String> schemaList = getResult(dbMetaData.getSchemas(), TABLE_SCHEM);
        String[] types = { "TABLE" };

        for (String schema : schemaList) {
            ResultSet rs2 = null;
            try {

                rs2 = conn.getMetaData().getTables(null, schema, null, types);
                if (rs2.next())
                    set.add(schema);
                else
                    log.debug(schema + " schema contains no table.  Ignore in VDS");

                /***  take too long to check empty tables
                Set<String> tableList = getResult(conn.getMetaData().getTables(null, schema, null, types), TABLE_NAME);
                Set<String> tableWithColsList = getResult(conn.getMetaData().getColumns(null, schema, null, null), TABLE_NAME);
                        
                if (tableList.size() == 0) {
                log.debug(schema + " schema contains no table.  Ignore in VDS");
                continue;
                } else {
                set.add(schema);
                        
                // does all tables contain columns
                boolean doesAllTablesContainCols = true;
                for (String tableName : tableList) {
                    if (!tableWithColsList.contains(tableName)) {
                        log.debug(schema + "." +  tableName + " table contains table with no column.  Ignore in VDS");
                        doesAllTablesContainCols = false;
                        break;
                    }
                }
                if (doesAllTablesContainCols) set.add(schema);
                        
                }
                ****/
            } catch (SQLException ex2) {
                log.debug("Fail to read schema, " + schema + ".  Ignore in VDS");
                ex2.printStackTrace();

            } finally {
                if (rs2 != null)
                    rs2.close();
            }
        }
        return set;
    } catch (SQLException ex) {
        log.error("Cannot get schemas", ex);
        throw ex;
    }
}

From source file:com.sun.licenseserver.License.java

/**
 * Retrieve a license from the database that belongs to the given 
 * userID, contentID and shopID combination.
 * /*w  w  w.  j av a2s . c  o  m*/
 * @param userID
 * @param contentID
 * @param shopID
 * @return
 * @throws LicenseServerException 
 */
public static License getLicenseFromDatabase(String userID, String contentID, String shopID)
        throws LicenseServerException {
    m_log.finer("Entering Function..");
    m_log.fine("Find license for user=[" + userID + "]contentID=[" + contentID + "]shopID=[" + shopID + "]");
    ResultSet rs = null;
    License lic = null;
    Blob license = null;
    String id = "";
    String mime = "";
    String expression = "select license, id, mime from sunLsLicenses where contentId= '" + contentID
            + "' and shopId='" + shopID + "' and userId='" + userID + "'";
    DatabaseHelper dbh = DatabaseHelper.getDatabaseHelper();
    rs = dbh.executeStatementWithResults(expression);
    // The check below is not working. 
    // We need to invoke the beforeFirst() function on the 
    // result set after we have counted the number of entries in the result set.
    // The beforeFirst() method does not works and throws an exception.
    // A work around has to be found to reinstate this test.
    //
    //        if (dbh.countNumberInResultSet(rs) > 1) {
    //            m_log.severe("More than one license retrieved for a given userID, contentID and shopID combo");
    //            throw new LicenseServerException(LicenseServerException.EC_NO_ERROR_CODE,
    //                                             "More than one license retrieved for a given userID, contentID and shopID combo");
    //        }
    try {
        if (rs != null && rs.next()) {
            ;
            license = rs.getBlob("license");
            id = rs.getObject("id").toString();
            mime = rs.getObject("mime").toString();
            id = id == null ? "" : id;
            mime = mime == null ? "" : mime;
            lic = new License(id, userID, contentID, shopID, mime, license.getBinaryStream());
        }
        dbh.releaseResultSetResources(rs);
    } catch (SQLException e) {
        m_log.severe("Error in retrieveing license from result set");
        e.printStackTrace();
        throw new LicenseServerException(LicenseServerException.EC_NO_ERROR_CODE,
                "Error in retrieveing license from result set");
    }
    m_log.finer("Leaving Function..");
    return lic;
}

From source file:com.wso2.raspberrypi.Util.java

public static void updateKeyValuePair(String key, String value) {
    BasicDataSource ds = getBasicDataSource();
    Connection dbConnection = null;
    PreparedStatement prepStmt = null;
    try {/*from   w  w  w .  j a  v  a  2s .co m*/
        dbConnection = ds.getConnection();
        prepStmt = dbConnection.prepareStatement("UPDATE KV_PAIR SET v='" + value + "' where k='" + key + "'");
        prepStmt.execute();
    } catch (SQLException e) {
        e.printStackTrace();
    } finally {
        try {
            if (dbConnection != null) {
                dbConnection.close();
            }
            if (prepStmt != null) {
                prepStmt.close();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}

From source file:com.wso2.raspberrypi.Util.java

public static void releasePi(String macAddress) {
    System.out.println("Releasing RPi " + macAddress);
    BasicDataSource ds = getBasicDataSource();
    Connection dbConnection = null;
    PreparedStatement prepStmt = null;
    try {//from  w  w w .j a  va2 s .c o m
        dbConnection = ds.getConnection();
        prepStmt = dbConnection.prepareStatement("UPDATE RASP_PI SET owner='' where mac='" + macAddress + "'");
        prepStmt.execute();
    } catch (SQLException e) {
        e.printStackTrace();
    } finally {
        try {
            if (dbConnection != null) {
                dbConnection.close();
            }
            if (prepStmt != null) {
                prepStmt.close();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}

From source file:com.wso2.raspberrypi.Util.java

public static void deleteRaspberryPi(String mac) {
    System.out.println("Removing Raspberry Pi: " + mac);
    BasicDataSource ds = getBasicDataSource();
    Connection dbConnection = null;
    PreparedStatement prepStmt = null;
    try {//from   www . j a  v a 2s  . c  o m
        dbConnection = ds.getConnection();
        prepStmt = dbConnection.prepareStatement("DELETE FROM RASP_PI WHERE mac='" + mac + "'");
        prepStmt.execute();
    } catch (SQLException e) {
        e.printStackTrace();
    } finally {
        try {
            if (dbConnection != null) {
                dbConnection.close();
            }
            if (prepStmt != null) {
                prepStmt.close();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}

From source file:com.wso2.raspberrypi.Util.java

public static void updateRaspberryPi(RaspberryPi raspberryPi) {
    BasicDataSource ds = getBasicDataSource();
    Connection dbConnection = null;
    PreparedStatement prepStmt = null;
    try {/*  ww w  .j  a va2  s  . c  o  m*/
        dbConnection = ds.getConnection();
        prepStmt = dbConnection.prepareStatement("UPDATE RASP_PI SET blink=" + raspberryPi.isBlink()
                + ",reboot=" + raspberryPi.isReboot() + ",selected=" + raspberryPi.isSelected() + ",label='"
                + raspberryPi.getLabel() + "'" + " where mac='" + raspberryPi.getMacAddress() + "'");
        prepStmt.execute();
    } catch (SQLException e) {
        e.printStackTrace();
    } finally {
        try {
            if (dbConnection != null) {
                dbConnection.close();
            }
            if (prepStmt != null) {
                prepStmt.close();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}

From source file:com.wso2.raspberrypi.Util.java

public static void clearAllRaspberryPis() throws RaspberryPiException {
    List<RaspberryPi> raspberryPis = getRaspberryPis(null);
    for (RaspberryPi raspberryPi : raspberryPis) {
        if (raspberryPi.getReservedFor() != null && !raspberryPi.getReservedFor().isEmpty()) {
            throw new RaspberryPiException("Cannot clear Raspberry Pis because some are reserved");
        }/*from  w ww. j  a v a  2s .c  o  m*/
    }
    System.out.println("Removing all Raspberry Pis...");
    BasicDataSource ds = getBasicDataSource();
    Connection dbConnection = null;
    PreparedStatement prepStmt = null;
    try {
        dbConnection = ds.getConnection();
        prepStmt = dbConnection.prepareStatement("DELETE FROM RASP_PI");
        prepStmt.execute();
    } catch (SQLException e) {
        e.printStackTrace();
    } finally {
        try {
            if (dbConnection != null) {
                dbConnection.close();
            }
            if (prepStmt != null) {
                prepStmt.close();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}

From source file:com.kylinolap.query.test.KylinTestBase.java

protected static void closeConnection(Connection connection) {
    if (connection != null) {
        try {/*from w  w  w. j a  v a2 s . c o m*/
            connection.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}

From source file:com.wso2.raspberrypi.Util.java

public static String getValue(String key) {
    String value = null;/*from w w  w .j  a v  a  2s .  c  om*/
    BasicDataSource ds = getBasicDataSource();

    Connection dbConnection = null;
    PreparedStatement prepStmt = null;
    ResultSet rs = null;
    try {
        dbConnection = ds.getConnection();
        prepStmt = dbConnection.prepareStatement("SELECT * FROM KV_PAIR WHERE k='" + key + "'");
        rs = prepStmt.executeQuery();

        while (rs.next()) {
            value = rs.getString("v");
        }
    } catch (SQLException e) {
        e.printStackTrace();
    } finally {
        try {
            if (dbConnection != null) {
                dbConnection.close();
            }
            if (prepStmt != null) {
                prepStmt.close();
            }
            if (rs != null) {
                rs.close();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
    return value;
}