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.BQScrollableResultSetFunctionTest.java

@Test
public void TestResultSetAbsolute() {
    try {/*from   ww w .j a v a 2 s.  com*/
        Assert.assertTrue(BQScrollableResultSetFunctionTest.Result.absolute(1));
        Assert.assertEquals("you", BQScrollableResultSetFunctionTest.Result.getString(1));
        Assert.assertTrue(BQScrollableResultSetFunctionTest.Result.absolute(2));
        Assert.assertEquals("yet", BQScrollableResultSetFunctionTest.Result.getString(1));
        Assert.assertTrue(BQScrollableResultSetFunctionTest.Result.absolute(3));
        Assert.assertEquals("would", BQScrollableResultSetFunctionTest.Result.getString(1));
        Assert.assertTrue(BQScrollableResultSetFunctionTest.Result.absolute(4));
        Assert.assertEquals("world", BQScrollableResultSetFunctionTest.Result.getString(1));
        Assert.assertTrue(BQScrollableResultSetFunctionTest.Result.absolute(5));
        Assert.assertEquals("without", BQScrollableResultSetFunctionTest.Result.getString(1));
        Assert.assertTrue(BQScrollableResultSetFunctionTest.Result.absolute(6));
        Assert.assertEquals("with", BQScrollableResultSetFunctionTest.Result.getString(1));
        Assert.assertTrue(BQScrollableResultSetFunctionTest.Result.absolute(7));
        Assert.assertEquals("your", BQScrollableResultSetFunctionTest.Result.getString(1));
        Assert.assertTrue(BQScrollableResultSetFunctionTest.Result.absolute(8));
        Assert.assertEquals("young", BQScrollableResultSetFunctionTest.Result.getString(1));
        Assert.assertTrue(BQScrollableResultSetFunctionTest.Result.absolute(9));
        Assert.assertEquals("words", BQScrollableResultSetFunctionTest.Result.getString(1));
        Assert.assertTrue(BQScrollableResultSetFunctionTest.Result.absolute(10));
        Assert.assertEquals("word", BQScrollableResultSetFunctionTest.Result.getString(1));
    } catch (SQLException e) {
        this.logger.error("SQLexception" + e.toString());
        Assert.fail("SQLException" + e.toString());
    }

    try {
        Assert.assertFalse(BQScrollableResultSetFunctionTest.Result.absolute(0));
        Assert.assertEquals("", BQScrollableResultSetFunctionTest.Result.getString(1));
    } catch (SQLException e) {
        boolean ct = e.toString().contains("Cursor is not in a valid Position");
        if (ct == true) {
            Assert.assertTrue(ct);
        } else {
            this.logger.error("SQLexception" + e.toString());
            Assert.fail("SQLException" + e.toString());
        }
    }

    try {
        Assert.assertFalse(BQScrollableResultSetFunctionTest.Result.absolute(11));
        Assert.assertEquals("", BQScrollableResultSetFunctionTest.Result.getString(1));
    } catch (SQLException e) {
        boolean ct = e.toString().contains("Cursor is not in a valid Position");
        if (ct == true) {
            Assert.assertTrue(ct);
        } else {
            this.logger.error("SQLexception" + e.toString());
            Assert.fail("SQLException" + e.toString());
        }
    }
}

From source file:BQJDBC.QueryResultTest.BQResultSetFunctionTest.java

/**
 * For testing isValid() , Close() , isClosed()
 *///from  w ww .j  av a  2s. c o  m
@Test
public void isClosedValidtest() {
    try {
        Assert.assertEquals(true, BQResultSetFunctionTest.con.isValid(0));
    } catch (SQLException e) {
        Assert.fail("Got an exception" + e.toString());
        e.printStackTrace();
    }
    try {
        Assert.assertEquals(true, BQResultSetFunctionTest.con.isValid(10));
    } catch (SQLException e) {
        Assert.fail("Got an exception" + e.toString());
        e.printStackTrace();
    }
    try {
        BQResultSetFunctionTest.con.isValid(-10);
    } catch (SQLException e) {
        Assert.assertTrue(true);
        // e.printStackTrace();
    }

    try {
        BQResultSetFunctionTest.con.close();
    } catch (SQLException e) {
        e.printStackTrace();
    }
    try {
        Assert.assertTrue(BQResultSetFunctionTest.con.isClosed());
    } catch (SQLException e1) {
        e1.printStackTrace();
    }

    try {
        BQResultSetFunctionTest.con.isValid(0);
    } catch (SQLException e) {
        Assert.assertTrue(true);
        e.printStackTrace();
    }

}

From source file:BQJDBC.QueryResultTest.BQResultSetFunctionTest.java

@Test
public void TestResultSetPrevious() {
    try {//ww w .j  a v a 2s .  c o  m
        Assert.assertTrue(BQResultSetFunctionTest.Result.last());
        Assert.assertTrue(BQResultSetFunctionTest.Result.previous());
        Assert.assertEquals("words", BQResultSetFunctionTest.Result.getString(1));
        Assert.assertTrue(BQResultSetFunctionTest.Result.previous());
        Assert.assertEquals("young", BQResultSetFunctionTest.Result.getString(1));
        Assert.assertTrue(BQResultSetFunctionTest.Result.previous());
        Assert.assertEquals("your", BQResultSetFunctionTest.Result.getString(1));
        Assert.assertTrue(BQResultSetFunctionTest.Result.previous());
        Assert.assertEquals("with", BQResultSetFunctionTest.Result.getString(1));
        Assert.assertTrue(BQResultSetFunctionTest.Result.previous());
        Assert.assertEquals("without", BQResultSetFunctionTest.Result.getString(1));
        Assert.assertTrue(BQResultSetFunctionTest.Result.previous());
        Assert.assertEquals("world", BQResultSetFunctionTest.Result.getString(1));
        Assert.assertTrue(BQResultSetFunctionTest.Result.previous());
        Assert.assertEquals("would", BQResultSetFunctionTest.Result.getString(1));
        Assert.assertTrue(BQResultSetFunctionTest.Result.previous());
        Assert.assertEquals("yet", BQResultSetFunctionTest.Result.getString(1));
        Assert.assertTrue(BQResultSetFunctionTest.Result.previous());
        Assert.assertEquals("you", BQResultSetFunctionTest.Result.getString(1));
        Assert.assertFalse(BQResultSetFunctionTest.Result.previous());
    } catch (SQLException e) {
        this.logger.error("SQLexception" + e.toString());
        Assert.fail("SQLException" + e.toString());
    }
    try {
        Assert.assertEquals("", BQResultSetFunctionTest.Result.getString(1));
    } catch (SQLException e) {
        boolean ct = e.toString().contains("Cursor is not in a valid Position");
        if (ct == true) {
            Assert.assertTrue(ct);
        } else {
            this.logger.error("SQLexception" + e.toString());
            Assert.fail("SQLException" + e.toString());
        }
    }
}

From source file:BQJDBC.QueryResultTest.BQResultSetFunctionTest.java

@Test
public void TestResultSetNext() {
    try {//  w ww  .jav a 2 s .  c om
        Assert.assertTrue(BQResultSetFunctionTest.Result.first());
        Assert.assertTrue(BQResultSetFunctionTest.Result.next());
        Assert.assertEquals("yet", BQResultSetFunctionTest.Result.getString(1));
        Assert.assertTrue(BQResultSetFunctionTest.Result.next());
        Assert.assertEquals("would", BQResultSetFunctionTest.Result.getString(1));
        Assert.assertTrue(BQResultSetFunctionTest.Result.next());
        Assert.assertEquals("world", BQResultSetFunctionTest.Result.getString(1));
        Assert.assertTrue(BQResultSetFunctionTest.Result.next());
        Assert.assertEquals("without", BQResultSetFunctionTest.Result.getString(1));
        Assert.assertTrue(BQResultSetFunctionTest.Result.next());
        Assert.assertEquals("with", BQResultSetFunctionTest.Result.getString(1));
        Assert.assertTrue(BQResultSetFunctionTest.Result.next());
        Assert.assertEquals("your", BQResultSetFunctionTest.Result.getString(1));
        Assert.assertTrue(BQResultSetFunctionTest.Result.next());
        Assert.assertEquals("young", BQResultSetFunctionTest.Result.getString(1));
        Assert.assertTrue(BQResultSetFunctionTest.Result.next());
        Assert.assertEquals("words", BQResultSetFunctionTest.Result.getString(1));
        Assert.assertTrue(BQResultSetFunctionTest.Result.next());
        Assert.assertEquals("word", BQResultSetFunctionTest.Result.getString(1));
        Assert.assertFalse(BQResultSetFunctionTest.Result.next());
    } catch (SQLException e) {
        this.logger.error("SQLexception" + e.toString());
        Assert.fail("SQLException" + e.toString());
    }

    try {
        Assert.assertEquals("", BQResultSetFunctionTest.Result.getString(1));
    } catch (SQLException e) {
        boolean ct = e.toString().contains("Cursor is not in a valid Position");
        if (ct == true) {
            Assert.assertTrue(ct);
        } else {
            this.logger.error("SQLexception" + e.toString());
            Assert.fail("SQLException" + e.toString());
        }
    }
}

From source file:BQJDBC.QueryResultTest.BQResultSetFunctionTest.java

@Test
public void TestResultIndexOutofBound() {
    try {//from  w  w  w.j av  a2 s  .c o  m
        this.logger.debug(BQResultSetFunctionTest.Result.getBoolean(99));
    } catch (SQLException e) {
        Assert.assertTrue(true);
        this.logger.error("SQLexception" + e.toString());
    }
}

From source file:BQJDBC.QueryResultTest.BQResultSetFunctionTest.java

@Test
public void TestResultSetRelative() {
    try {/*w ww  . j a v a2 s.c  o  m*/
        Assert.assertTrue(BQResultSetFunctionTest.Result.absolute(1));
        Assert.assertEquals("you", BQResultSetFunctionTest.Result.getString(1));
        Assert.assertTrue(BQResultSetFunctionTest.Result.relative(1));
        Assert.assertEquals("yet", BQResultSetFunctionTest.Result.getString(1));
        Assert.assertTrue(BQResultSetFunctionTest.Result.relative(2));
        Assert.assertEquals("world", BQResultSetFunctionTest.Result.getString(1));
        Assert.assertTrue(BQResultSetFunctionTest.Result.relative(5));
        Assert.assertEquals("words", BQResultSetFunctionTest.Result.getString(1));
        Assert.assertTrue(BQResultSetFunctionTest.Result.relative(-5));
        Assert.assertEquals("world", BQResultSetFunctionTest.Result.getString(1));
        Assert.assertTrue(BQResultSetFunctionTest.Result.relative(-2));
        Assert.assertEquals("yet", BQResultSetFunctionTest.Result.getString(1));
        Assert.assertTrue(BQResultSetFunctionTest.Result.relative(-1));
        Assert.assertEquals("you", BQResultSetFunctionTest.Result.getString(1));
    } catch (SQLException e) {
        this.logger.error("SQLexception" + e.toString());
        Assert.fail("SQLException" + e.toString());
    }
    try {
        Assert.assertTrue(BQResultSetFunctionTest.Result.first());
        Assert.assertFalse(BQResultSetFunctionTest.Result.relative(-1));
        Assert.assertEquals("", BQResultSetFunctionTest.Result.getString(1));
    } catch (SQLException e) {
        boolean ct = e.toString().contains("Cursor is not in a valid Position");
        if (ct == true) {
            Assert.assertTrue(ct);
        } else {
            this.logger.error("SQLexception" + e.toString());
            Assert.fail("SQLException" + e.toString());
        }
    }

    try {
        Assert.assertTrue(BQResultSetFunctionTest.Result.last());
        Assert.assertFalse(BQResultSetFunctionTest.Result.relative(1));
        Assert.assertEquals("", BQResultSetFunctionTest.Result.getString(1));
    } catch (SQLException e) {
        boolean ct = e.toString().contains("Cursor is not in a valid Position");
        if (ct == true) {
            Assert.assertTrue(ct);
        } else {
            this.logger.error("SQLexception" + e.toString());
            Assert.fail("SQLException" + e.toString());
        }
    }
}

From source file:BQJDBC.QueryResultTest.BQResultSetFunctionTest.java

@Test
public void TestResultSetAbsolute() {
    try {//from ww w  .j a v a2s.c  om
        Assert.assertTrue(BQResultSetFunctionTest.Result.absolute(1));
        Assert.assertEquals("you", BQResultSetFunctionTest.Result.getString(1));
        Assert.assertTrue(BQResultSetFunctionTest.Result.absolute(2));
        Assert.assertEquals("yet", BQResultSetFunctionTest.Result.getString(1));
        Assert.assertTrue(BQResultSetFunctionTest.Result.absolute(3));
        Assert.assertEquals("would", BQResultSetFunctionTest.Result.getString(1));
        Assert.assertTrue(BQResultSetFunctionTest.Result.absolute(4));
        Assert.assertEquals("world", BQResultSetFunctionTest.Result.getString(1));
        Assert.assertTrue(BQResultSetFunctionTest.Result.absolute(5));
        Assert.assertEquals("without", BQResultSetFunctionTest.Result.getString(1));
        Assert.assertTrue(BQResultSetFunctionTest.Result.absolute(6));
        Assert.assertEquals("with", BQResultSetFunctionTest.Result.getString(1));
        Assert.assertTrue(BQResultSetFunctionTest.Result.absolute(7));
        Assert.assertEquals("your", BQResultSetFunctionTest.Result.getString(1));
        Assert.assertTrue(BQResultSetFunctionTest.Result.absolute(8));
        Assert.assertEquals("young", BQResultSetFunctionTest.Result.getString(1));
        Assert.assertTrue(BQResultSetFunctionTest.Result.absolute(9));
        Assert.assertEquals("words", BQResultSetFunctionTest.Result.getString(1));
        Assert.assertTrue(BQResultSetFunctionTest.Result.absolute(10));
        Assert.assertEquals("word", BQResultSetFunctionTest.Result.getString(1));
    } catch (SQLException e) {
        this.logger.error("SQLexception" + e.toString());
        Assert.fail("SQLException" + e.toString());
    }

    try {
        Assert.assertFalse(BQResultSetFunctionTest.Result.absolute(0));
        Assert.assertEquals("", BQResultSetFunctionTest.Result.getString(1));
    } catch (SQLException e) {
        boolean ct = e.toString().contains("Cursor is not in a valid Position");
        if (ct == true) {
            Assert.assertTrue(ct);
        } else {
            this.logger.error("SQLexception" + e.toString());
            Assert.fail("SQLException" + e.toString());
        }
    }

    try {
        Assert.assertFalse(BQResultSetFunctionTest.Result.absolute(11));
        Assert.assertEquals("", BQResultSetFunctionTest.Result.getString(1));
    } catch (SQLException e) {
        boolean ct = e.toString().contains("Cursor is not in a valid Position");
        if (ct == true) {
            Assert.assertTrue(ct);
        } else {
            this.logger.error("SQLexception" + e.toString());
            Assert.fail("SQLException" + e.toString());
        }
    }
}

From source file:dbProcs.Getter.java

/**
 * @param ApplicationRoot The current running context of the application
 * @return Result set containing class info in the order classId, className and then classYear
 *///from  w  w w .  ja va 2s. com
public static ResultSet getClassInfo(String ApplicationRoot) {
    ResultSet result = null;
    log.debug("*** Getter.getClassInfo (All Classes) ***");
    Connection conn = Database.getCoreConnection(ApplicationRoot);
    try {
        CallableStatement callstmt = conn.prepareCall("call classesGetData()");
        log.debug("Gathering classesGetData ResultSet");
        result = callstmt.executeQuery();
        log.debug("Returning Result Set from classesGetData");
    } catch (SQLException e) {
        log.error("Could not execute query: " + e.toString());
        result = null;
    }
    log.debug("*** END getClassInfo");
    return result;
}

From source file:dbProcs.Getter.java

/**
 * @param ApplicationRoot The current running context of the application
 * @return The amount of classes currently existing in the database
 *//*from ww  w .  j  av a 2  s . co m*/
public static int getClassCount(String ApplicationRoot) {
    int result = 0;
    ResultSet resultSet = null;
    log.debug("*** Getter.getClassCount ***");
    Connection conn = Database.getCoreConnection(ApplicationRoot);
    try {
        CallableStatement callstmt = conn.prepareCall("call classCount()");
        log.debug("Gathering classCount ResultSet");
        resultSet = callstmt.executeQuery();
        log.debug("Opening Result Set from classCount");
        resultSet.next();
        result = resultSet.getInt(1);
    } catch (SQLException e) {
        log.error("Could not execute query: " + e.toString());
        result = 0;
    }
    Database.closeConnection(conn);
    log.debug("*** END getClassCount");
    return result;
}

From source file:dbProcs.Getter.java

/**
 * @param ApplicationRoot The current running context of the application
 * @param classId The identifier of the class
 * @return String Array with Class information with the format of {name, year}
 *//*from  ww  w . j  av  a 2s  .c om*/
public static String[] getClassInfo(String ApplicationRoot, String classId) {
    String[] result = new String[2];
    log.debug("*** Getter.getClassInfo (Single Class) ***");
    Connection conn = Database.getCoreConnection(ApplicationRoot);
    try {
        CallableStatement callstmt = conn.prepareCall("call classFind(?)");
        callstmt.setString(1, classId);
        log.debug("Gathering classFind ResultSet");
        ResultSet resultSet = callstmt.executeQuery();
        log.debug("Opening Result Set from classFind");
        resultSet.next();
        result[0] = resultSet.getString(1);//Name
        result[1] = resultSet.getString(2);//Year
    } catch (SQLException e) {
        log.error("Could not execute query: " + e.toString());
        result = null;
    }
    log.debug("*** END getClassInfo");
    return result;
}