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:controlador.Peticiones.java

private void primerInsert(int idmesa) {
    r = bd.ejecutarSelect("select * from pedidos where mesas_idmesa=" + idmesa + " order by fechapedido desc");
    try {/*from w  w w  .j a  va  2s.com*/
        if (r.next()) {
            pedido = r.getInt("idpedido");
            estado = r.getInt("estadopedido");
            ;
        }
    } catch (SQLException ex) {
        System.out.println(ex.toString());
    }
}

From source file:eionet.gdem.qa.XQueryTask.java

/**
 * Read data from the DB where it is stored for further processing.
 *//*from   w  w  w  . j a  v a  2s  . c o m*/
private void initVariables() {
    try {
        String[] jobData = xqJobDao.getXQJobData(jobId);
        if (jobData == null) {
            handleError("No such job: " + jobId, true);
        }
        url = jobData[0];
        scriptFile = jobData[1];
        resultFile = jobData[2]; // just a file name, file is not created
        queryID = jobData[5];
        scriptType = jobData[8];
    } catch (SQLException sqe) {
        handleError("Error getting WQ data from the DB: " + sqe.toString(), true);
    }
}

From source file:org.apache.sqoop.manager.sqlserver.SQLServerManagerManualTest.java

@Test
public void testReadMissingTable() {
    ResultSet results = null;/* w  ww .  java 2 s.com*/
    try {
        String[] colNames = { "*" };
        results = manager.readTable(MISSING_TABLE, colNames);
        assertNull("Expected null resultset from readTable(MISSING_TABLE)", results);
    } catch (SQLException sqlException) {
        // we actually expect this pass.
    } finally {
        if (null != results) {
            try {
                results.close();
            } catch (SQLException sqlE) {
                fail("SQL Exception in ResultSet.close(): " + sqlE.toString());
            }
        }

        manager.release();
    }
}

From source file:com.groupon.odo.proxylib.SQLService.java

/**
 * Only meant to be called once//from  w w  w .  j a v a  2s  .c om
 */
public void startServer() throws Exception {
    if (!externalDatabaseHost) {
        try {
            this.port = Utils.getSystemPort(Constants.SYS_DB_PORT);
            server = Server.createTcpServer("-tcpPort", String.valueOf(port), "-tcpAllowOthers").start();
        } catch (SQLException e) {
            if (e.toString().contains("java.net.UnknownHostException")) {
                logger.error(
                        "Startup failure. Potential bug in OSX & Java7. Workaround: add name of local machine to '/etc/hosts.'");
                logger.error("Example: 127.0.0.1 MacBook");
                throw e;
            }
        }
    }
}

From source file:org.apache.sqoop.manager.sqlserver.SQLServerQueryManualTest.java

public void tearDown() {
    super.tearDown();
    MSSQLTestUtils utils = new MSSQLTestUtils();
    try {/*from w  w w . j a  va2  s.  com*/
        utils.dropTableIfExists("TPCH1M_LINEITEM");
    } catch (SQLException e) {
        LOG.error("TearDown fail with SQLException: " + StringUtils.stringifyException(e));
        fail("TearDown fail with SQLException: " + e.toString());
    }
}

From source file:BQJDBC.QueryResultTest.BQForwardOnlyResultSetFunctionTest.java

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

    try {
        Assert.assertEquals("", BQForwardOnlyResultSetFunctionTest.Result.getString(1));
    } catch (SQLException e) {
        Assert.assertTrue(true);
    }
}

From source file:com.cloudera.sqoop.manager.DirectMySQLTest.java

@After
public void tearDown() {
    super.tearDown();

    if (null != manager) {
        try {/*from   w  ww  .jav a2s  .  c om*/
            manager.close();
            manager = null;
        } catch (SQLException sqlE) {
            LOG.error("Got SQLException: " + sqlE.toString());
            fail("Got SQLException: " + sqlE.toString());
        }
    }
}

From source file:BQJDBC.QueryResultTest.BQForwardOnlyResultSetFunctionTest.java

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

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

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

}

From source file:BQJDBC.QueryResultTest.BQForwardOnlyResultSetFunctionTest.java

@Test
public void ChainedCursorFunctionTest() {
    this.logger.info("ChainedFunctionTest");
    try {/* w  ww  .j  a  v  a  2s .  com*/
        Assert.assertTrue(BQForwardOnlyResultSetFunctionTest.Result.next());
        Assert.assertEquals("you", BQForwardOnlyResultSetFunctionTest.Result.getString(1));

    } catch (SQLException e) {
        this.logger.error("SQLexception" + e.toString());
        Assert.fail("SQLException" + e.toString());
    }
    try {
        BQForwardOnlyResultSetFunctionTest.Result.absolute(10);
    } catch (SQLException e) {
        Assert.assertTrue(true);
    }

    try {
        for (int i = 0; i < 9; i++) {
            Assert.assertTrue(BQForwardOnlyResultSetFunctionTest.Result.next());
        }
        Assert.assertFalse(BQForwardOnlyResultSetFunctionTest.Result.next());
    } catch (SQLException e) {
        this.logger.error("SQLexception" + e.toString());
        Assert.fail("SQLException" + e.toString());
    }

    try {
        Assert.assertEquals("", BQForwardOnlyResultSetFunctionTest.Result.getString(1));
    } catch (SQLException e) {
        Assert.assertTrue(true);
    }

    QueryLoad();
    try {
        Result.next();
        Assert.assertEquals("you", BQForwardOnlyResultSetFunctionTest.Result.getString(1));
    } catch (SQLException e) {
        this.logger.error("SQLexception" + e.toString());
        Assert.fail("SQLException" + e.toString());
    }
    this.logger.info("chainedfunctiontest end");
}

From source file:com.cloudera.sqoop.mapreduce.db.DataDrivenDBInputFormat.java

@Override
/** {@inheritDoc} */
public List<InputSplit> getSplits(JobContext job) throws IOException {

    int targetNumTasks = ConfigurationHelper.getJobNumMaps(job);
    if (1 == targetNumTasks) {
        // There's no need to run a bounding vals query; just return a split
        // that separates nothing. This can be considerably more optimal for a
        // large table with no index.
        List<InputSplit> singletonSplit = new ArrayList<InputSplit>();
        singletonSplit.add(new DataDrivenDBInputSplit("1=1", "1=1"));
        return singletonSplit;
    }//w ww .ja va 2s  .  com

    ResultSet results = null;
    Statement statement = null;
    Connection connection = getConnection();
    try {
        statement = connection.createStatement();

        results = statement.executeQuery(getBoundingValsQuery());
        results.next();

        // Based on the type of the results, use a different mechanism
        // for interpolating split points (i.e., numeric splits, text splits,
        // dates, etc.)
        int sqlDataType = results.getMetaData().getColumnType(1);
        DBSplitter splitter = getSplitter(sqlDataType);
        if (null == splitter) {
            throw new IOException("Unknown SQL data type: " + sqlDataType);
        }

        return splitter.split(job.getConfiguration(), results, getDBConf().getInputOrderBy());
    } catch (SQLException e) {
        throw new IOException(e.getMessage());
    } finally {
        // More-or-less ignore SQL exceptions here, but log in case we need it.
        try {
            if (null != results) {
                results.close();
            }
        } catch (SQLException se) {
            LOG.debug("SQLException closing resultset: " + se.toString());
        }

        try {
            if (null != statement) {
                statement.close();
            }
        } catch (SQLException se) {
            LOG.debug("SQLException closing statement: " + se.toString());
        }

        try {
            connection.commit();
            closeConnection();
        } catch (SQLException se) {
            LOG.debug("SQLException committing split transaction: " + se.toString());
        }
    }
}