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:ca.hec.cdm.jobs.ImportZC1CatalogDescriptionJob.java

private Connection getZC1Connection() {

    String driverName = ServerConfigurationService.getString("hec.zonecours.conn.portail.driver.name");
    String url = ServerConfigurationService.getString("hec.zonecours.conn.portail.url");
    String user = ServerConfigurationService.getString("hec.zonecours.conn.portail.user");
    String password = ServerConfigurationService.getString("hec.zonecours.conn.portail.password");

    Connection zc1con = null;/*  w ww  .  j  av a  2s .  c om*/

    try {
        Class.forName(driverName);

        zc1con = DriverManager.getConnection(url, user, password);
    } catch (ClassNotFoundException cnf) {
        log.error("Driver not found !");
    } catch (SQLException sqlex) {
        log.error("Database connection error:" + sqlex.toString());
    }

    return zc1con;
}

From source file:com.cloudera.sqoop.TestAllTables.java

@Before
public void setUp() {
    // start the server
    super.setUp();

    if (useHsqldbTestServer()) {
        // throw away TWOINTTABLE and things we don't care about.
        try {/*from   w w  w  .jav  a  2s  . co  m*/
            this.getTestServer().dropExistingSchema();
        } catch (SQLException sqlE) {
            fail(sqlE.toString());
        }
    }

    this.tableNames = new ArrayList<String>();
    this.expectedStrings = new ArrayList<String>();

    // create two tables.
    this.expectedStrings.add("A winner");
    this.expectedStrings.add("is you!");
    this.expectedStrings.add(null);

    int i = 0;
    for (String expectedStr : this.expectedStrings) {
        String wrappedStr = null;
        if (expectedStr != null) {
            wrappedStr = "'" + expectedStr + "'";
        }

        String[] types = { "INT NOT NULL PRIMARY KEY", "VARCHAR(32)" };
        String[] vals = { Integer.toString(i++), wrappedStr };
        this.createTableWithColTypes(types, vals);
        this.tableNames.add(this.getTableName());
        this.removeTableDir();
        incrementTableNum();
    }
}

From source file:org.castor.cpa.persistence.sql.keygen.SequenceBeforeKeyGenerator.java

/**
 * @param conn An open connection within the given transaction.
 * @param tableName The table name./*ww  w.  jav a  2 s  .  c o m*/
 * @param primKeyName The primary key name.
 * @return A new key.
 * @throws PersistenceException An error occured talking to persistent storage.
 */
public Object generateKey(final Connection conn, final String tableName, final String primKeyName)
        throws PersistenceException {
    PreparedStatement stmt = null;
    ResultSet rs = null;

    try {
        // prepares the statement
        String sql = _factory.getSequenceBeforeSelectString(getSeqName(tableName, primKeyName), tableName,
                _increment);
        stmt = conn.prepareStatement(sql);

        // execute the prepared statement
        rs = stmt.executeQuery();

        // process result set using appropriate handler and return its value
        return _typeHandler.getValue(rs);
    } catch (SQLException e) {
        String msg = Messages.format("persist.keyGenSQL", this.getClass().getName(), e.toString());
        throw new PersistenceException(msg);
    } finally {
        try {
            if (rs != null) {
                rs.close();
            }
            if (stmt != null) {
                stmt.close();
            }
        } catch (SQLException e) {
            LOG.warn("Problem closing JDBC statement", e);
        }
    }
}

From source file:org.vietspider.server.handler.DataContentHandler.java

@SuppressWarnings("unused")
public void execute(final HttpRequest request, final HttpResponse response, final HttpContext context,
        OutputStream output) throws Exception {
    Header header = request.getFirstHeader("action");
    String action = header.getValue();

    byte[] bytes = getRequestData(request);

    String value = new String(bytes, Application.CHARSET).trim();

    if ("load.new.list.metas".equals(action)) {
        String alert = SystemProperties.getInstance().getValue("alert.new.articles");
        if ("false".equals(alert) || (Application.LICENSE == Install.SEARCH_SYSTEM
                && (alert == null || alert.trim().isEmpty()))) {
            ArticleCollection collection = new ArticleCollection();
            String text = Object2XML.getInstance().toXMLDocument(collection).getTextValue();
            output.write(text.getBytes(Application.CHARSET));
            return;
        }//from   w  ww  .  j  av  a  2 s  .  c o m

        /* MetaList metas = new MetaList("vietspider");
         metas.setPageSize(10);
         metas.setCurrentPage(1);
                 
         Calendar calendar = Calendar.getInstance();
         String date = CalendarUtils.getDateFormat().format(calendar.getTime());
                
         //working with entry
         EntryReader entryReader = new EntryReader();
         IEntryDomain entryDomain = null;
         entryDomain = new SimpleEntryDomain(date, null, null);
         entryReader.read(entryDomain, metas, -1);*/

        ArticleCollection collection = new ArticleCollection();
        AlertQueue.createInstance().get(collection);

        //      List<Article> articles = metas.getData();
        //      collection.get().addAll(articles);

        String text = Object2XML.getInstance().toXMLDocument(collection).getTextValue();
        output.write(text.getBytes(Application.CHARSET));

        return;
    }

    if ("load.article".equals(action)) {
        Article article = null;
        try {
            article = DatabaseService.getLoader().loadArticle(value);
            StringBuilder builder = new StringBuilder(article.getMeta().getTitle());
            builder.append('\n').append(article.getMeta().getDesc());
            output.write(builder.toString().getBytes(Application.CHARSET));
        } catch (SQLException e) {
            output.write(("error\n" + e.toString()).getBytes());
        } catch (Exception e) {
            output.write(("error\n" + e.toString()).getBytes());
        }
        return;
    }

    if ("load.article.by.url".equals(action)) {
        //      if(!DataGetter.class.isInstance(DatabaseService.getLoader())) {
        if (DatabaseService.isMode(DatabaseService.RDBMS)) {
            output.write(new byte[0]);
            return;
        }

        TextSpliter spliter = new TextSpliter();
        String[] elements = spliter.toArray(value, '\n');
        if (elements.length != 2) {
            output.write(new byte[0]);
            return;
        }

        String articleId = DatabaseService.getLoader().loadIdByURL(elements[1]);
        if (articleId == null) {
            output.write(new byte[0]);
            return;
        }

        Article article = null;
        try {
            article = DatabaseService.getLoader().loadArticle(articleId);
            if (article == null) {
                output.write(new byte[0]);
                return;
            }

            if (!article.getDomain().getGroup().equals(elements[0])) {
                output.write(new byte[0]);
                return;
            }

            ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
            ObjectOutputStream out = new ObjectOutputStream(byteOutputStream);
            out.writeObject(article);
            out.flush();
            out.close();

            bytes = byteOutputStream.toByteArray();
            bytes = new GZipIO().zip(bytes);

            output.write(bytes);
        } catch (SQLException e) {
            output.write(new byte[0]);
        } catch (Exception e) {
            output.write(new byte[0]);
        }
        return;
    }
}

From source file:org.apache.hadoop.sqoop.manager.TestSqlManager.java

@Test
public void testReadTable() {
    try {//from   w w w  . j  av a 2 s. co  m
        ResultSet results = manager.readTable(HsqldbTestServer.getTableName(),
                HsqldbTestServer.getFieldNames());

        assertNotNull("ResultSet from readTable() is null!", results);

        ResultSetMetaData metaData = results.getMetaData();
        assertNotNull("ResultSetMetadata is null in readTable()", metaData);

        // ensure that we get the correct number of columns back
        assertEquals("Number of returned columns was unexpected!", metaData.getColumnCount(),
                HsqldbTestServer.getFieldNames().length);

        // should get back 4 rows. They are:
        // 1 2
        // 3 4
        // 5 6
        // 7 8
        // .. so while order isn't guaranteed, we should get back 16 on the left and 20 on the right.
        int sumCol1 = 0, sumCol2 = 0, rowCount = 0;
        while (results.next()) {
            rowCount++;
            sumCol1 += results.getInt(1);
            sumCol2 += results.getInt(2);
        }

        assertEquals("Expected 4 rows back", EXPECTED_NUM_ROWS, rowCount);
        assertEquals("Expected left sum of 16", EXPECTED_COL1_SUM, sumCol1);
        assertEquals("Expected right sum of 20", EXPECTED_COL2_SUM, sumCol2);
    } catch (SQLException sqlException) {
        fail("SQL Exception: " + sqlException.toString());
    }
}

From source file:itesm.mx.golpedecalor.SelectGroupActivity.java

@Override
protected void onResume() {
    try {// w w  w . j  av a  2  s.com
        dbo.open();
    } catch (SQLException ex) {
        Log.e("", ex.toString());
    }

    grupos = new ArrayList(dbo.getAllGroups());

    nombres = new ArrayList<>();

    for (Grupo g : grupos) {
        nombres.add(g.getNombre());
    }

    adapter = new ArrayAdapter<String>(this, R.layout.activity_row, R.id.rowTV, nombres);
    miembrosLV.setAdapter(adapter);
    registerForContextMenu(miembrosLV);
    registerForContextMenu(miembrosLV);

    super.onResume();
}

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

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

    if (null != this.conn) {
        try {//from  w  w  w . j  a  va2s.c  o  m
            this.conn.close();
        } catch (SQLException sqlE) {
            LOG.error("Got SQLException closing conn: " + sqlE.toString());
        }
    }

    if (null != manager) {
        try {
            manager.close();
            manager = null;
        } catch (SQLException sqlE) {
            LOG.error("Got SQLException: " + sqlE.toString());
            fail("Got SQLException: " + sqlE.toString());
        }
    }
}

From source file:ca.hec.cdm.jobs.ImportZC1CatalogDescriptionJob.java

public void execute(JobExecutionContext arg0) throws JobExecutionException {

    Connection connex = getZC1Connection();
    PreparedStatement ps = null;/*from w  w w  .  j a  v  a 2 s.  c o  m*/

    try {
        ps = connex.prepareStatement(ZC1_REQUEST);

        ResultSet rs = ps.executeQuery();

        while (rs.next()) {

            String koid = rs.getString(1);
            Clob htmlClob = rs.getClob(2);

            // ajouter pour la table plancours
            if (koid.substring(0, 2).equalsIgnoreCase("a-")) {
                koid = koid.substring(2);
            }

            String courseId = FormatUtils.formatCourseId(koid);

            String html = htmlClob.getSubString((long) 1, (int) htmlClob.length());
            String desc = formatHtml(html);

            if (desc != null) {
                saveInZC2(courseId, desc);
            } else {
                log.error("No description found in ZC1 for: " + courseId);
                noDesc++;
            }

        } // end while

        log.error("----------------------------------------------------------------------------------");
        log.error("FIN DE LA JOB");
        log.error("saved desc:" + savedDesc);
        log.error("unknow desc:" + unknownDesc);
        log.error("no desc found:" + noDesc);
        log.error("Description is not null:" + notNullDesc);
    } catch (SQLException sqex) {
        log.error("Error database: " + sqex.toString());
    } finally {
        try {
            ps.close();
        } catch (Exception ex) {
        }
        try {
            connex.close();
        } catch (Exception ex) {
        }
    }

}

From source file:org.apache.hadoop.sqoop.manager.TestSqlManager.java

@Test
public void getPrimaryKeyFromTable() {
    // first, create a table with a primary key
    Connection conn = null;/*  www.  j  ava2s.c  o m*/
    try {
        conn = testServer.getConnection();
        PreparedStatement statement = conn.prepareStatement(
                "CREATE TABLE " + TABLE_WITH_KEY + "(" + KEY_FIELD_NAME + " INT NOT NULL PRIMARY KEY, foo INT)",
                ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
        statement.executeUpdate();
    } catch (SQLException sqlException) {
        fail("Could not create table with primary key: " + sqlException.toString());
    } finally {
        if (null != conn) {
            try {
                conn.close();
            } catch (SQLException sqlE) {
                LOG.warn("Got SQLException during close: " + sqlE.toString());
            }
        }
    }

    String primaryKey = manager.getPrimaryKey(TABLE_WITH_KEY);
    assertEquals("Expected null pkey for table without key", primaryKey, KEY_FIELD_NAME);
}

From source file:itesm.mx.golpedecalor.MonitoringActivity.java

@Override
protected void onResume() {
    try {// w  w  w. ja va2 s .  com
        dbo.open();
    } catch (SQLException ex) {
        Log.e("", ex.toString());
    }
    super.onResume();
}