Example usage for java.sql SQLException getMessage

List of usage examples for java.sql SQLException getMessage

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:bizlogic.Records.java

public static void add(Connection DBcon, String sensor_name, String smpl_interval, String running, String name)
        throws SQLException {

    String isRunning;/*from  www  .  ja  v a 2  s . co m*/
    Statement st;
    ResultSet rs = null;

    try {
        st = DBcon.createStatement();
        rs = st.executeQuery("SELECT * FROM USERCONF.SENSORLIST WHERE NAME = '" + sensor_name + "' ");

    } catch (SQLException ex) {
        Logger lgr = Logger.getLogger(Records.class.getName());
        lgr.log(Level.SEVERE, ex.getMessage(), ex);
    }
    rs.next();
    int id = rs.getInt("sensor_id");

    String sql_statement;
    if (running.equals("true")) {
        isRunning = "B'1'";
    } else {
        isRunning = "B'0'";
    }

    st = DBcon.createStatement();
    sql_statement = "INSERT INTO USERCONF.LOG_LIST(SENSOR_ID, SMPL_INTERVAL, RUNNING, NAME) " + "VALUES (" + id
            + ", " + smpl_interval + ", " + isRunning + ", " + "'" + name + "'" + " );";
    System.out.println(sql_statement);
    st.clearBatch();
    st = DBcon.createStatement();
    DBcon.createStatement();
    st.executeUpdate(sql_statement);

}

From source file:com.hp.test.framework.generatejellytess.GenerateJellyTests.java

public static void maptestcasesapi(String GID, String Testcase, int expresults, String Model_xml_path)
        throws IOException, ClassNotFoundException {
    Map<String, String> Locators1;
    Map<String, Map<String, String>> mapping_list = new HashMap<>();
    BufferedWriter fw;//from ww w.j a va  2 s .co  m
    File f = null;
    f = File.createTempFile("tmp", ".xml", new File(mp.getProperty("TEMP_LOCATION")));

    //        String update_exp_results_temp = mp.getProperty("UPDATE_RESULTS");
    //
    //        boolean update_exp_results = false;
    //        if (update_exp_results_temp.equals("yes")) {
    //            update_exp_results = true;
    //
    //        }
    fw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f), "UTF-8"));
    fw.write("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>");
    fw.write(Testcase);
    fw.close();

    String path = f.getAbsolutePath();
    Locators.clear();
    Locators1 = GetLocators(path);
    // f.delete();
    for (String key : Locators1.keySet()) {
        //  System.out.println("key" + key);
        String temp_ar[] = key.split("_");
        String parent = temp_ar[0];
        String child = temp_ar[1];
        String UI_object = temp_ar[2];

        if (!mapping_list.containsKey(parent)) {
            // System.out.println("parent"+parent);
            Map<String, String> innerMap = mapping_list.get(key);
            if (innerMap == null) {
                mapping_list.put(parent, innerMap = new HashMap<>()); // Java version >= 1.7
            }
            innerMap.put(child + ":" + UI_object, Locators1.get(key));

            mapping_list.put(parent, innerMap);
        } else {
            Map<String, String> innerMap = mapping_list.get(parent);
            innerMap.put(child + ":" + UI_object, Locators1.get(key));
            mapping_list.put(parent, innerMap);
            //  mapping_list.put(parent, mapping_list.get(parent)+ "^"+child +":"+ UI_object + ":"+ Locators1.get(key));
        }
    }

    Locators.clear();
    //Map<String, String> mapping_api_list = GetLocators(mp.getProperty("UI_API_MAPPING_XML_PATH"));
    // Generating jelly scripts
    //        String generate_jelly_tests = mp.getProperty("GENERATE_JELLY_TESTS").toLowerCase();

    //   ArrayList order_list = GetRootnodes.GetrootLocators(mp.getProperty("MODEL_XML_PATH"));---Remove
    ArrayList order_list = GetRootnodes.GetrootLocators(Model_xml_path);

    try {

        String jellyFile = temp_jelly_Tests_location + "\\" + GID + "_" + glb_Feature_Name + ".xml";// mp.getProperty("JELLY_TESTS_LOCATION") + "Jelly_" + model_name + "_GID" + GID;
        String[] temp_ar = GID.split("_");
        int TestCase_GID = Integer.valueOf(temp_ar[3]);
        CreateJellyTestCase.createUITests(TestCase_GID, order_list, mapping_list, jellyFile,
                mp.getProperty("OBJECT_REPOSITORY_XML_PATH"));
        CreateReadableTestCase.createRedableTests(order_list, mapping_list,
                mp.getProperty("OBJECT_REPOSITORY_XML_PATH"));

    } catch (SQLException e) {
        log.error("Exception in updating Expected Results" + e.getMessage());
    }

    //**** end of Generating Jelly script file
}

From source file:io.mycat.server.packet.util.CharsetUtil.java

private static boolean getCharsetCollationFromMysql(DBHostConfig config) {
    String sql = "SELECT ID,CHARACTER_SET_NAME,COLLATION_NAME,IS_DEFAULT FROM INFORMATION_SCHEMA.COLLATIONS";
    try (Connection conn = getConnection(config)) {
        if (conn == null)
            return false;

        try (Statement statement = conn.createStatement()) {
            ResultSet rs = statement.executeQuery(sql);
            while (rs != null && rs.next()) {
                int collationIndex = new Long(rs.getLong(1)).intValue();
                String charsetName = rs.getString(2);
                String collationName = rs.getString(3);
                boolean isDefaultCollation = (rs.getString(4) != null
                        && "Yes".equalsIgnoreCase(rs.getString(4))) ? true : false;

                INDEX_TO_CHARSET.put(collationIndex, charsetName);
                if (isDefaultCollation) { // ? charsetName collationIndexcollationIndex
                    CHARSET_TO_INDEX.put(charsetName, collationIndex);
                }/*w  ww. ja va2  s .co m*/

                CharsetCollation cc = new CharsetCollation(charsetName, collationIndex, collationName,
                        isDefaultCollation);
                COLLATION_TO_CHARSETCOLLATION.put(collationName, cc);
            }
            if (COLLATION_TO_CHARSETCOLLATION.size() > 0)
                return true;
            return false;
        } catch (SQLException e) {
            logger.warn(e.getMessage());
        }

    } catch (SQLException e) {
        logger.warn(e.getMessage());
    }
    return false;
}

From source file:jongo.jdbc.JDBCExecutor.java

/**
 * Executes the given {@link jongo.sql.Delete} object
 * @param delete a {@link jongo.sql.Delete} instance
 * @return number of records deleted/* w  w  w.ja v  a2  s .  com*/
 * @throws SQLException from the QueryRunner
 * @see org.apache.commons.dbutils.QueryRunner
 */
public static int delete(final Delete delete) throws SQLException {
    l.debug(delete.toString());
    DatabaseConfiguration dbconf = conf.getDatabaseConfiguration(delete.getTable().getDatabase());
    QueryRunner run = JDBCConnectionFactory.getQueryRunner(dbconf);
    Dialect dialect = DialectFactory.getDialect(dbconf);

    try {
        int deleted = run.update(dialect.toStatementString(delete), JongoUtils.parseValue(delete.getId()));
        l.debug("Deleted " + deleted + " records.");
        return deleted;
    } catch (SQLException ex) {
        l.debug(ex.getMessage());
        throw ex;
    }
}

From source file:jongo.jdbc.JDBCExecutor.java

/**
 * Executes a given {@link jongo.sql.Select} object and returns the metadata associated to the results.
 * @param select a {@link jongo.sql.Select} instance which should only retrieve one result.
 * @return a List of {@link jongo.rest.xstream.Row} with the metadata obtained 
 * with the {@link jongo.sql.Select} statement
 * @throws SQLException SQLException from the QueryRunner
 * @see org.apache.commons.dbutils.QueryRunner
 * @see jongo.handler.ResultSetMetaDataHandler
 *///from   w  ww  . java2s  .  c  om
public static List<Row> getTableMetaData(final Select select) throws SQLException {
    l.debug("Obtaining metadata from table " + select.toString());

    ResultSetHandler<List<Row>> res = new ResultSetMetaDataHandler();

    DatabaseConfiguration dbconf = conf.getDatabaseConfiguration(select.getTable().getDatabase());
    QueryRunner run = JDBCConnectionFactory.getQueryRunner(dbconf);
    Dialect dialect = DialectFactory.getDialect(dbconf);

    try {
        List<Row> results = run.query(dialect.toStatementString(select), res);
        l.debug("Received " + results.size() + " results.");
        return results;
    } catch (SQLException ex) {
        l.debug(ex.getMessage());
        throw ex;
    }
}

From source file:jongo.jdbc.JDBCExecutor.java

/**
 * Executes the given {@link jongo.sql.Update} object
 * @param update a {@link jongo.sql.Update} instance
 * @return a List of {@link jongo.rest.xstream.Row} with the modified records
 * @throws SQLException from the QueryRunner
 * @see org.apache.commons.dbutils.QueryRunner
 *//*w w  w .j  a v  a 2s.com*/
public static List<Row> update(final Update update) throws SQLException {
    l.debug(update.toString());

    DatabaseConfiguration dbconf = conf.getDatabaseConfiguration(update.getTable().getDatabase());
    QueryRunner run = JDBCConnectionFactory.getQueryRunner(dbconf);
    Dialect dialect = DialectFactory.getDialect(dbconf);

    List<Row> results = new ArrayList<Row>();
    try {
        int ret = run.update(dialect.toStatementString(update), JongoUtils.parseValues(update.getParameters()));
        if (ret != 0) {
            results = get(update.getSelect(), false);
        }
    } catch (SQLException ex) {
        l.error(ex.getMessage());
        throw ex;
    }
    l.debug("Updated " + results.size() + " records.");
    return results;
}

From source file:jongo.jdbc.JDBCExecutor.java

/**
 * Executes the given {@link org.jongo.jdbc.DynamicFinder} object.
 * @param database database name or schema where to execute the {@link org.jongo.jdbc.DynamicFinder}
 * @param df an instance of {@link org.jongo.jdbc.DynamicFinder}
 * @param limit an instance of {@link jongo.jdbc.LimitParam}
 * @param order an instance of {@link jongo.jdbc.OrderParam}
 * @param params a vararg of Object instances used as parameters for the QueryRunner.
 * @return a List of {@link jongo.rest.xstream.Row} with the records found by the DynamicFinder.
 * @throws SQLException from the QueryRunner
 * @see org.apache.commons.dbutils.QueryRunner
 * @see jongo.sql.dialect.Dialect//ww  w.ja  v  a2  s.  c o  m
 */
public static List<Row> find(final String database, final DynamicFinder df, final LimitParam limit,
        final OrderParam order, Object... params) throws SQLException {
    l.debug(df.getSql());
    l.debug(JongoUtils.varargToString(params));

    DatabaseConfiguration dbconf = conf.getDatabaseConfiguration(database);
    Dialect dialect = DialectFactory.getDialect(dbconf);
    String query = dialect.toStatementString(df, limit, order);

    QueryRunner run = JDBCConnectionFactory.getQueryRunner(dbconf);
    ResultSetHandler<List<Row>> res = new JongoResultSetHandler(true);
    try {
        List<Row> results = run.query(query, res, params);
        l.debug("Received " + results.size() + " results.");
        return results;
    } catch (SQLException ex) {
        l.debug(ex.getMessage());
        throw ex;
    }
}

From source file:jongo.jdbc.JDBCExecutor.java

/**
 * Executes the given {@link jongo.sql.Insert} object
 * @param insert a {@link jongo.sql.Insert} instance
 * @return number of records inserted/*w w  w .  ja v  a2s  . c  o m*/
 * @throws SQLException from the QueryRunner
 * @see org.apache.commons.dbutils.QueryRunner
 */
public static int insert(final Insert insert) throws SQLException {
    l.debug(insert.toString());

    DatabaseConfiguration dbconf = conf.getDatabaseConfiguration(insert.getTable().getDatabase());
    QueryRunner run = JDBCConnectionFactory.getQueryRunner(dbconf);
    Dialect dialect = DialectFactory.getDialect(dbconf);

    try {
        int inserted;
        if (insert.getColumns().isEmpty())
            inserted = run.update(dialect.toStatementString(insert));
        else
            inserted = run.update(dialect.toStatementString(insert),
                    JongoUtils.parseValues(insert.getValues()));

        l.debug("Inserted " + inserted + " records.");
        return inserted;
    } catch (SQLException ex) {
        l.debug(ex.getMessage());
        throw ex;
    }
}

From source file:jongo.jdbc.JDBCExecutor.java

/**
 * Executes the given {@link jongo.sql.Select} object and returns all or one record depending on the value
 * of the allRecords variable/*from  w  ww . j a va  2  s. c  o m*/
 * @param select a {@link jongo.sql.Select} instance
 * @param allRecords return all (true) records or one (false) record.
 * @return a List of {@link jongo.rest.xstream.Row} with the records found by the statement.
 * @throws SQLException from the QueryRunner
 * @see org.apache.commons.dbutils.QueryRunner
 * @see jongo.handler.JongoResultSetHandler
 */
public static List<Row> get(final Select select, final boolean allRecords) throws SQLException {
    l.debug(select.toString());
    List<Row> response = null;

    DatabaseConfiguration dbconf = conf.getDatabaseConfiguration(select.getTable().getDatabase());
    QueryRunner run = JDBCConnectionFactory.getQueryRunner(dbconf);
    Dialect dialect = DialectFactory.getDialect(dbconf);

    ResultSetHandler<List<Row>> res = new JongoResultSetHandler(allRecords);

    if (select.isAllRecords()) {
        try {
            response = run.query(dialect.toStatementString(select), res);
        } catch (SQLException ex) {
            l.debug(ex.getMessage());
            throw ex;
        }
    } else {
        try {
            response = run.query(dialect.toStatementString(select), res,
                    JongoUtils.parseValue(select.getParameter().getValue()));
        } catch (SQLException ex) {
            l.debug(ex.getMessage());
            throw ex;
        }
    }

    return response;
}

From source file:bizlogic.Records.java

public static void writeCSV(Connection DBcon, String record_id) throws SQLException {

    Statement st;// w  ww. j  a  v  a  2  s  . c  o  m
    ResultSet rs = null;

    System.out.println("WriteCSV started");

    try {
        st = DBcon.createStatement();
        rs = st.executeQuery("SELECT * FROM PUBLIC.t" + record_id);
        System.out.println("Result set read finished");
    } catch (SQLException ex) {
        Logger lgr = Logger.getLogger(Records.class.getName());
        lgr.log(Level.SEVERE, ex.getMessage(), ex);
    }

    try {

        String DELIMITER = ",";
        String NEW_LINE = "\n";
        String FILE_HEADER = "Time,Series";

        System.out.println("Delete old file");
        FileWriter csvFile = new FileWriter("/var/lib/tomcat8/webapps/ROOT/Records/Data/" + record_id + ".csv");

        //BufferedWriter csvFile = new BufferedWriter(
        //        new OutputStreamWriter(new FileOutputStream(new File(
        //                "/var/lib/tomcat8/webapps/ROOT/Records/Data/" + 
        //                        record_id + ".csv"))));

        csvFile.write("");

        csvFile.append(FILE_HEADER);
        csvFile.append(NEW_LINE);

        Calendar calendar = new GregorianCalendar();

        System.out.println("Writing file...");
        while (rs.next()) {

            long time_stamp = rs.getLong("time");
            double value = rs.getDouble("value");
            String _year;
            String _month;
            String _day;
            String _hour;
            String _min;
            String _sec;

            calendar.setTimeInMillis(time_stamp);

            _year = Integer.toString(calendar.get(Calendar.YEAR));
            _month = Integer.toString(calendar.get(Calendar.MONTH) + 1);
            _day = Integer.toString(calendar.get(Calendar.DAY_OF_MONTH));
            _hour = Integer.toString(calendar.get(Calendar.HOUR_OF_DAY));
            _min = Integer.toString(calendar.get(Calendar.MINUTE));
            _sec = Integer.toString(calendar.get(Calendar.SECOND));

            csvFile.append(_year + "/" + _month + "/" + _day + " " + _hour + ":" + _min + ":" + _sec + DELIMITER
                    + Double.toString(value) + NEW_LINE); //new Date("2009/07/19 12:34:56")

        }
        System.out.print("File written");
        rs.close();
        //csvFile.flush();
        csvFile.close();
    }

    catch (IOException ex) {
        Logger.getLogger(Records.class.getName()).log(Level.WARNING, null, ex);
    }
}