Example usage for java.sql SQLException toString

List of usage examples for java.sql SQLException toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:BQJDBC.QueryResultTest.QueryResultTest.java

@Test
public void QueryResultTest10() {
    final String sql = "SELECT corpus_date,SUM(word_count) FROM publicdata:samples.shakespeare GROUP BY corpus_date ORDER BY corpus_date DESC LIMIT 5;";
    // final String description =
    // "A query which gets how many words Shapespeare wrote in a year (5 years displayed descending)";
    /*/*from   ww w . j a  va  2s. c o m*/
     * String[][] expectation = new String[][] {
     * {"1612","1611","1610","1609","1608"},
     * {"26265","17593","26181","57073","19846"} };
     */

    this.logger.info("Test number: 10");
    this.logger.info("Running query:" + sql);

    try {
        Statement stmt = QueryResultTest.con.createStatement();
        stmt.setQueryTimeout(1);
        stmt.executeQuery(sql);
    } catch (SQLException e) {
        this.logger.info("SQLexception" + e.toString());
        Assert.assertTrue(true);
    }

}

From source file:BQJDBC.QueryResultTest.QueryResultTest.java

@Test
public void QueryResultTest05() {
    final String sql = "SELECT word FROM publicdata:samples.shakespeare WHERE word='huzzah' ;";
    final String description = "The word \"huzzah\" NOTE: It doesn't appear in any any book, so it returns with a null #WHERE";

    this.logger.info("Test number: 05");
    this.logger.info("Running query:" + sql);

    java.sql.ResultSet Result = null;
    try {/*from w  w w .j  a  v  a 2 s. c om*/
        Result = QueryResultTest.con.createStatement().executeQuery(sql);
        this.logger.debug(Result.getMetaData().getColumnCount());
    } catch (SQLException e) {
        this.logger.error("SQLexception" + e.toString());
        Assert.fail("SQLException" + e.toString());
    }
    Assert.assertNotNull(Result);

    this.logger.debug(description);
    try {
        if (Result.getType() != ResultSet.TYPE_FORWARD_ONLY)
            Assert.assertFalse(Result.first());
    } catch (SQLException e) {
        this.logger.error("SQLexception" + e.toString());
        Assert.fail(e.toString());
    }
}

From source file:BQJDBC.QueryResultTest.QueryResultTest.java

@Test
public void QueryResultTest02() {
    final String sql = "SELECT corpus FROM publicdata:samples.shakespeare GROUP BY corpus ORDER BY corpus LIMIT 5";
    final String description = "The book names of shakespeare #GROUP_BY #ORDER_BY";
    String[][] expectation = new String[][] {
            { "1kinghenryiv", "1kinghenryvi", "2kinghenryiv", "2kinghenryvi", "3kinghenryvi" } };
    this.logger.info("Test number: 02");
    this.logger.info("Running query:" + sql);

    java.sql.ResultSet Result = null;
    try {// www.  ja v a2 s . c  o  m
        Result = QueryResultTest.con.createStatement().executeQuery(sql);
    } catch (SQLException e) {
        this.logger.error("SQLexception" + e.toString());
        Assert.fail("SQLException" + e.toString());
    }
    Assert.assertNotNull(Result);

    this.logger.debug(description);
    HelperFunctions.printer(expectation);
    try {
        Assert.assertTrue("Comparing failed in the String[][] array",
                this.comparer(expectation, BQSupportMethods.GetQueryResult(Result)));
    } catch (SQLException e) {
        this.logger.error("SQLexception" + e.toString());
        Assert.fail(e.toString());
    }
}

From source file:BQJDBC.QueryResultTest.QueryResultTest.java

@Test
public void QueryResultTest04() {
    final String sql = "SELECT corpus FROM publicdata:samples.shakespeare WHERE LOWER(word)=\"lord\" GROUP BY corpus ORDER BY corpus DESC LIMIT 5;";
    final String description = "A query which gets 5 of Shakespeare were the word lord is present";
    String[][] expectation = new String[][] {
            { "winterstale", "various", "twogentlemenofverona", "twelfthnight", "troilusandcressida" } };

    this.logger.info("Test number: 04");
    this.logger.info("Running query:" + sql);

    java.sql.ResultSet Result = null;
    try {//from  w w w . j av a2  s  .c  o m
        Result = QueryResultTest.con.createStatement().executeQuery(sql);
    } catch (SQLException e) {
        this.logger.error("SQLexception" + e.toString());
        Assert.fail("SQLException" + e.toString());
    }
    Assert.assertNotNull(Result);

    this.logger.debug(description);
    HelperFunctions.printer(expectation);
    try {
        Assert.assertTrue("Comparing failed in the String[][] array",
                this.comparer(expectation, BQSupportMethods.GetQueryResult(Result)));
    } catch (SQLException e) {
        this.logger.error("SQLexception" + e.toString());
        Assert.fail(e.toString());
    }
}

From source file:BQJDBC.QueryResultTest.QueryResultTest.java

@Test
public void QueryResultTest06() {
    final String sql = "SELECT corpus_date,SUM(word_count) FROM publicdata:samples.shakespeare GROUP BY corpus_date ORDER BY corpus_date DESC LIMIT 5;";
    final String description = "A query which gets how many words Shapespeare wrote in a year (5 years displayed descending)";
    String[][] expectation = new String[][] { { "1612", "1611", "1610", "1609", "1608" },
            { "26265", "17593", "26181", "57073", "19846" } };

    this.logger.info("Test number: 06");
    this.logger.info("Running query:" + sql);

    java.sql.ResultSet Result = null;
    try {/*from w  w  w. j  a  va2 s. co m*/
        Result = QueryResultTest.con.createStatement().executeQuery(sql);
    } catch (SQLException e) {
        this.logger.error("SQLexception" + e.toString());
        Assert.fail("SQLException" + e.toString());
    }
    Assert.assertNotNull(Result);

    this.logger.debug(description);
    HelperFunctions.printer(expectation);
    try {
        Assert.assertTrue("Comparing failed in the String[][] array",
                this.comparer(expectation, BQSupportMethods.GetQueryResult(Result)));
    } catch (SQLException e) {
        this.logger.error("SQLexception" + e.toString());
        Assert.fail(e.toString());
    }
}

From source file:BQJDBC.QueryResultTest.QueryResultTest.java

@Test
public void QueryResultTest09() {
    final String sql = "SELECT corpus, corpus_date FROM publicdata:samples.shakespeare GROUP BY corpus, corpus_date ORDER BY corpus_date DESC LIMIT 3;";
    final String description = "Shakespeare's 3 latest";
    String[][] expectation = new String[][] { { "kinghenryviii", "tempest", "winterstale" },
            { "1612", "1611", "1610" } };

    this.logger.info("Test number: 09");
    this.logger.info("Running query:" + sql);

    java.sql.ResultSet Result = null;
    try {/*w w w .  j av  a  2 s  .  c o  m*/
        Result = QueryResultTest.con.createStatement().executeQuery(sql);
    } catch (SQLException e) {
        this.logger.error("SQLexception" + e.toString());
        Assert.fail("SQLException" + e.toString());
    }
    Assert.assertNotNull(Result);

    this.logger.debug(description);

    HelperFunctions.printer(expectation);

    try {
        Assert.assertTrue("Comparing failed in the String[][] array",
                this.comparer(expectation, BQSupportMethods.GetQueryResult(Result)));
    } catch (SQLException e) {
        this.logger.error("SQLexception" + e.toString());
        Assert.fail(e.toString());
    }
}

From source file:com.mapd.utility.SQLImporter.java

void executeQuery() {
    Connection conn = null;/*from   w ww.  ja v a  2 s .c o  m*/
    Statement stmt = null;

    long totalTime = 0;

    try {
        //Open a connection
        LOGGER.info("Connecting to database url :" + cmd.getOptionValue("jdbcConnect"));
        conn = DriverManager.getConnection(cmd.getOptionValue("jdbcConnect"), cmd.getOptionValue("sourceUser"),
                cmd.getOptionValue("sourcePasswd"));

        long startTime = System.currentTimeMillis();

        //Execute a query
        stmt = conn.createStatement();

        long timer;
        ResultSet rs = stmt.executeQuery(cmd.getOptionValue("sqlStmt"));

        //check if table already exists and is compatible in MapD with the query metadata
        ResultSetMetaData md = rs.getMetaData();
        checkMapDTable(md);

        timer = System.currentTimeMillis();

        long resultCount = 0;
        int bufferCount = 0;
        long total = 0;
        int bufferSize = Integer.valueOf(cmd.getOptionValue("bufferSize", "10000"));

        List<TStringRow> rows = new ArrayList(bufferSize);
        while (rs.next()) {
            TStringRow tsr = new TStringRow();
            for (int i = 1; i <= md.getColumnCount(); i++) {
                // place string in rows array
                TStringValue tsv = new TStringValue();
                tsv.str_val = rs.getString(i);
                if (rs.wasNull()) {
                    tsv.is_null = true;
                } else {
                    tsv.is_null = false;
                }
                tsr.addToCols(tsv);
            }
            rows.add(tsr);

            resultCount++;
            bufferCount++;
            if (bufferCount == bufferSize) {
                bufferCount = 0;
                //send the buffer to mapD
                client.load_table(session, cmd.getOptionValue("targetTable"), rows);
                rows.clear();
                if (resultCount % 100000 == 0) {
                    LOGGER.info("Imported " + resultCount + " records");
                }
            }
        }
        if (bufferCount > 0) {
            //send the LAST buffer to mapD
            client.load_table(session, cmd.getOptionValue("targetTable"), rows);
            rows.clear();
            bufferCount = 0;
        }
        LOGGER.info("result set count is " + resultCount + " read time is "
                + (System.currentTimeMillis() - timer) + "ms");

        //Clean-up environment
        rs.close();
        stmt.close();

        totalTime = System.currentTimeMillis() - startTime;
        conn.close();
    } catch (SQLException se) {
        LOGGER.error("SQLException - " + se.toString());
        se.printStackTrace();
    } catch (TMapDException ex) {
        LOGGER.error("TMapDException - " + ex.toString());
        ex.printStackTrace();
    } catch (TException ex) {
        LOGGER.error("TException failed - " + ex.toString());
        ex.printStackTrace();
    } finally {
        //finally block used to close resources
        try {
            if (stmt != null) {
                stmt.close();
            }
        } catch (SQLException se2) {
        } // nothing we can do
        try {
            if (conn != null) {
                conn.close();
            }
        } catch (SQLException se) {
            LOGGER.error("SQlException in close - " + se.toString());
            se.printStackTrace();
        } //end finally try
    } //end try
}

From source file:BQJDBC.QueryResultTest.QueryResultTest.java

@Test
public void QueryResultTest07() {
    final String sql = "SELECT corpus, SUM(word_count) as w_c FROM publicdata:samples.shakespeare GROUP BY corpus HAVING w_c > 20000 ORDER BY w_c ASC LIMIT 5;";
    final String description = "A query which gets Shakespeare were there are more words then 20000 (only 5 is displayed ascending)";
    String[][] expectation = new String[][] {
            { "juliuscaesar", "twelfthnight", "titusandronicus", "kingjohn", "tamingoftheshrew" },
            { "21052", "21633", "21911", "21983", "22358" } };

    this.logger.info("Test number: 07");
    this.logger.info("Running query:" + sql);

    java.sql.ResultSet Result = null;
    try {/*from  w w  w  . j a v a  2  s  . c  o  m*/
        Result = QueryResultTest.con.createStatement().executeQuery(sql);
    } catch (SQLException e) {
        this.logger.error("SQLexception" + e.toString());
        Assert.fail("SQLException" + e.toString());
    }
    Assert.assertNotNull(Result);

    this.logger.debug(description);

    HelperFunctions.printer(expectation);

    try {
        Assert.assertTrue("Comparing failed in the String[][] array",
                this.comparer(expectation, BQSupportMethods.GetQueryResult(Result)));
    } catch (SQLException e) {
        this.logger.error("SQLexception" + e.toString());
        Assert.fail(e.toString());
    }
}

From source file:BQJDBC.QueryResultTest.QueryResultTest.java

@Test
public void QueryResultTest08() {
    final String sql = "SELECT corpus, MAX(word_count) as m, word FROM publicdata:samples.shakespeare GROUP BY corpus,word ORDER BY m DESC LIMIT 5;";
    final String description = "A query which gets those Shakespeare with the most common word ordered by count descending (only 5 is displayed)";
    String[][] expectation = new String[][] {
            { "hamlet", "coriolanus", "kinghenryv", "2kinghenryiv", "kingrichardiii" },
            { "995", "942", "937", "894", "848" }, { "the", "the", "the", "the", "the" } };

    this.logger.info("Test number: 08");
    this.logger.info("Running query:" + sql);

    java.sql.ResultSet Result = null;
    try {//from   w  w w.  j a  v  a 2s.c o  m
        Result = QueryResultTest.con.createStatement().executeQuery(sql);
    } catch (SQLException e) {
        this.logger.error("SQLexception" + e.toString());
        Assert.fail("SQLException" + e.toString());
    }
    Assert.assertNotNull(Result);

    this.logger.debug(description);

    HelperFunctions.printer(expectation);

    try {
        Assert.assertTrue("Comparing failed in the String[][] array",
                this.comparer(expectation, BQSupportMethods.GetQueryResult(Result)));
    } catch (SQLException e) {
        this.logger.error("SQLexception" + e.toString());
        Assert.fail(e.toString());
    }
}

From source file:BQJDBC.QueryResultTest.QueryResultTest.java

@Test
public void QueryResultTest12() {
    int limitNum = 40000;
    final String sql = "SELECT weight_pounds  FROM publicdata:samples.natality LIMIT " + limitNum;

    this.logger.info("Test number: 12");
    this.logger.info("Running query:" + sql);

    java.sql.ResultSet Result = null;
    try {/*  w w  w.ja v a  2s  .co  m*/
        Statement stm = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        stm.setFetchSize(1000);
        Result = stm.executeQuery(sql);
    } catch (SQLException e) {
        this.logger.error("SQLexception" + e.toString());
        Assert.fail("SQLException" + e.toString());
    }
    Assert.assertNotNull(Result);
    try {/*
         int j = 0;
         for (int i = 0; i < limitNum-1; i++) {
         if(i%1000 == 0) {
             logger.debug("fetched 1k for the " + ++j + ". time");
         }
         Assert.assertTrue(Result.next());  
         }*/
        Result.absolute(limitNum);
        Assert.assertTrue(true);
    } catch (SQLException e) {
        e.printStackTrace();
        Assert.fail();
    }
}