当前位置: 首页>>代码示例>>Java>>正文


Java JdbcSQLException类代码示例

本文整理汇总了Java中org.h2.jdbc.JdbcSQLException的典型用法代码示例。如果您正苦于以下问题:Java JdbcSQLException类的具体用法?Java JdbcSQLException怎么用?Java JdbcSQLException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


JdbcSQLException类属于org.h2.jdbc包,在下文中一共展示了JdbcSQLException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createTable

import org.h2.jdbc.JdbcSQLException; //导入依赖的package包/类
private void createTable() {
    try {
        con = this.dataSource.getConnection();
        pstm = con.prepareStatement("CREATE TABLE IF NOT EXISTS device_location.gateway "
                + "(id BIGINT AUTO_INCREMENT PRIMARY KEY, longitude DECIMAL(9, 7), latitude DECIMAL(10, 7))");
        pstm.executeUpdate();

        System.out.println("'Gateway' table created");
    } catch (JdbcSQLException e) {
        e.printStackTrace(System.out);
        System.out.println("Table already exists");
    } catch (SQLException ex) {
        ex.printStackTrace(System.out);
        System.out.println("Table ERROR");
    }
}
 
开发者ID:WiserUFBA,项目名称:wiser-services,代码行数:17,代码来源:BdBean.java

示例2: selectOne

import org.h2.jdbc.JdbcSQLException; //导入依赖的package包/类
public Location selectOne(String id) {
    ResultSet rs_local;
    Location location;
    try {
        con = this.dataSource.getConnection();
        pstm = con.prepareStatement("SELECT * FROM device_location.gateway WHERE id=?;");
        pstm.setString(1, id);
        rs_local = pstm.executeQuery();
        
        if (rs_local.next()) {
            location = new Location();
            location.setId(rs_local.getLong("id"));
            location.setLatitude(rs_local.getFloat("latitude"));
            location.setLongitude(rs_local.getFloat("longitude"));
            return location;
        } else {
            return null;
        }
    } catch (JdbcSQLException e) {
        e.printStackTrace(System.out);
        return null;
    } catch (SQLException ex) {
        ex.printStackTrace(System.out);
        return null;
    }
}
 
开发者ID:WiserUFBA,项目名称:wiser-services,代码行数:27,代码来源:BdBean.java

示例3: selectAll

import org.h2.jdbc.JdbcSQLException; //导入依赖的package包/类
public ArrayList<Location> selectAll() {
    ResultSet rs_local;
    ArrayList<Location> ar = new ArrayList();
    try {
        con = this.dataSource.getConnection();
        pstm = con.prepareStatement("SELECT * FROM device_location.gateway");
        rs_local = pstm.executeQuery();
        while (rs_local.next()) {
            Location loc = new Location();
            //dm.setId(rs_local.getLong("id"));
            //dm.setLatitude(rs_local.getFloat("latitude"));
            //dm.setLongitude(rs_local.getFloat("longitude")); 
            ar.add(loc);
        }
        return ar;
    } catch (JdbcSQLException e) {
        e.printStackTrace(new PrintStream(System.err));
        return null;
    } catch (SQLException ex) {
        ex.printStackTrace(new PrintStream(System.err));
        return null;
    }
}
 
开发者ID:WiserUFBA,项目名称:wiser-services,代码行数:24,代码来源:BdBean.java

示例4: testDropColumn

import org.h2.jdbc.JdbcSQLException; //导入依赖的package包/类
/**
 *
 * @throws Exception if failed.
 */
public void testDropColumn() throws Exception {
    try {
        run("CREATE TABLE test (id INT PRIMARY KEY, a INT, b CHAR)");

        assertEquals(0, checkTableState(QueryUtils.DFLT_SCHEMA, "TEST",
            new QueryField("ID", Integer.class.getName(), true),
            new QueryField("A", Integer.class.getName(), true),
            new QueryField("B", String.class.getName(), true)));

        run("ALTER TABLE test DROP COLUMN a");

        assertEquals(0, checkTableState(QueryUtils.DFLT_SCHEMA, "TEST",
            new QueryField("ID", Integer.class.getName(), true),
            new QueryField("B", String.class.getName(), true)));

        run("ALTER TABLE test DROP COLUMN IF EXISTS a");

        assertThrowsAnyCause("ALTER TABLE test DROP COLUMN a", JdbcSQLException.class, "Column \"A\" not found");
    }
    finally {
        run("DROP TABLE IF EXISTS test");
    }
}
 
开发者ID:apache,项目名称:ignite,代码行数:28,代码来源:H2DynamicColumnsAbstractBasicSelfTest.java

示例5: assertCommandThrowsTableNotFound

import org.h2.jdbc.JdbcSQLException; //导入依赖的package包/类
/**
 * Check that given (non DDL) command throws an exception as expected.
 * @param checkedTblName Table name to expect in error message.
 * @param cmd Command to execute.
 */
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
private void assertCommandThrowsTableNotFound(String checkedTblName, final String cmd) {
    final Throwable e = GridTestUtils.assertThrowsWithCause(new Callable<Object>() {
        @Override public Object call() throws Exception {
            execute(cmd);

            return null;
        }
    }, JdbcSQLException.class);

    GridTestUtils.assertThrows(null, new Callable<Object>() {
        @SuppressWarnings("ConstantConditions")
        @Override public Object call() throws Exception {
            throw (Exception)e.getCause();
        }
    }, JdbcSQLException.class, "Table \"" + checkedTblName + "\" not found");
}
 
开发者ID:apache,项目名称:ignite,代码行数:23,代码来源:H2DynamicTableSelfTest.java

示例6: testWrongPassword

import org.h2.jdbc.JdbcSQLException; //导入依赖的package包/类
@Test(expected = JdbcSQLException.class)
public void testWrongPassword() throws Exception {
    String tempDir = System.getProperty("java.io.tmpdir");
    String dbPath = tempDir + File.separator + "jgt-dbs-testdbsmain1" + DB_TYPE.getExtensionOnCreation();
    TestUtilities.deletePrevious(tempDir, dbPath, DB_TYPE);

    try (ADb db = DB_TYPE.getDb()) {
        db.setCredentials("testuser", "testpwd");
        db.open(dbPath);
    }

    try (ADb db = DB_TYPE.getDb()) {
        db.setCredentials("testuser", "testpwd1");
        db.open(dbPath);
    }
}
 
开发者ID:TheHortonMachine,项目名称:hortonmachine,代码行数:17,代码来源:TestDbsPwdMain.java

示例7: dropAllTables

import org.h2.jdbc.JdbcSQLException; //导入依赖的package包/类
@Test
public void dropAllTables() throws Exception {
    Language language = resourceGenerate.aLanguage();
    dbServiceSpy.languageDao().createOrUpdate(language);
    assertLanguagesCount(dbServiceSpy, 1L);

    dbServiceSpy.dropAllTables();

    try {
        dbServiceSpy.languageDao().countOf();
        fail("Expected exception");
    } catch (JdbcSQLException ignore) {
    }
    for (Class aClass : dbServiceSpy.getTableClasses()) {
        verify(dbServiceSpy, times(2)).dropTable(aClass);
    }
}
 
开发者ID:massimozappino,项目名称:tagmycode-java-sdk,代码行数:18,代码来源:DbServiceTest.java

示例8: writeFile

import org.h2.jdbc.JdbcSQLException; //导入依赖的package包/类
private synchronized void writeFile(String s, Throwable t) {
    try {
        if (checkSize++ >= CHECK_SIZE_EACH_WRITES) {
            checkSize = 0;
            closeWriter();
            if (maxFileSize > 0 && FileUtils.size(fileName) > maxFileSize) {
                String old = fileName + ".old";
                FileUtils.delete(old);
                FileUtils.move(fileName, old);
            }
        }
        if (!openWriter()) {
            return;
        }
        printWriter.println(s);
        if (t != null) {
            if (levelFile == ERROR && t instanceof JdbcSQLException) {
                JdbcSQLException se = (JdbcSQLException) t;
                int code = se.getErrorCode();
                if (ErrorCode.isCommon(code)) {
                    printWriter.println(t.toString());
                } else {
                    t.printStackTrace(printWriter);
                }
            } else {
                t.printStackTrace(printWriter);
            }
        }
        printWriter.flush();
        if (closed) {
            closeWriter();
        }
    } catch (Exception e) {
        logWritingError(e);
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:37,代码来源:TraceSystem.java

示例9: convertToIOException

import org.h2.jdbc.JdbcSQLException; //导入依赖的package包/类
/**
 * Convert an exception to an IO exception.
 *
 * @param e the root cause
 * @return the IO exception
 */
public static IOException convertToIOException(Throwable e) {
    if (e instanceof IOException) {
        return (IOException) e;
    }
    if (e instanceof JdbcSQLException) {
        JdbcSQLException e2 = (JdbcSQLException) e;
        if (e2.getOriginalCause() != null) {
            e = e2.getOriginalCause();
        }
    }
    return new IOException(e.toString(), e);
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:19,代码来源:DbException.java

示例10: getLoginError

import org.h2.jdbc.JdbcSQLException; //导入依赖的package包/类
/**
 * Get the formatted login error message.
 *
 * @param e the exception
 * @param isH2 if the current database is a H2 database
 * @return the formatted error message
 */
private String getLoginError(Exception e, boolean isH2) {
    if (e instanceof JdbcSQLException &&
            ((JdbcSQLException) e).getErrorCode() == ErrorCode.CLASS_NOT_FOUND_1) {
        return "${text.login.driverNotFound}<br />" + getStackTrace(0, e, isH2);
    }
    return getStackTrace(0, e, isH2);
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:15,代码来源:WebApp.java

示例11: sendError

import org.h2.jdbc.JdbcSQLException; //导入依赖的package包/类
private byte[] sendError(Throwable t) {
    try {
    	byte[] resp = new byte[65536];
    	ByteBuffer bb = ByteBuffer.wrap(resp);
        SQLException e = DbException.convert(t).getSQLException();
        StringWriter writer = new StringWriter();
        e.printStackTrace(new PrintWriter(writer));
        String trace = writer.toString();
        String message;
        String sql;
        if (e instanceof JdbcSQLException) {
            JdbcSQLException j = (JdbcSQLException) e;
            message = j.getOriginalMessage();
            sql = j.getSQL();
        } else {
            message = e.getMessage();
            sql = null;
        }
        bb.putInt(SessionRemote.STATUS_ERROR);
        ByteBufferTool.putString(bb, e.getSQLState());
        ByteBufferTool.putString(bb, message);
        ByteBufferTool.putString(bb, sql);
        bb.putInt(e.getErrorCode());
        ByteBufferTool.putString(bb, trace);
        return ByteBufferTool.convertBB(bb);
    } catch (Exception e2) {
        /*if (!transfer.isClosed()) {
            server.traceError(e2);
        }*/
        // if writing the error does not work, close the connection
        stop = true;
        return null;
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:35,代码来源:TcpServerThread.java

示例12: getCreateSQL

import org.h2.jdbc.JdbcSQLException; //导入依赖的package包/类
@Override
public String getCreateSQL() {
    StringBuilder buff = new StringBuilder("CREATE FORCE ");
    if (isTemporary()) {
        if (globalTemporary) {
            buff.append("GLOBAL ");
        } else {
            buff.append("LOCAL ");
        }
        buff.append("TEMPORARY ");
    }
    buff.append("LINKED TABLE ").append(getSQL());
    if (comment != null) {
        buff.append(" COMMENT ").append(StringUtils.quoteStringSQL(comment));
    }
    buff.append('(').
        append(StringUtils.quoteStringSQL(driver)).
        append(", ").
        append(StringUtils.quoteStringSQL(url)).
        append(", ").
        append(StringUtils.quoteStringSQL(user)).
        append(", ").
        append(StringUtils.quoteStringSQL(password)).
        append(", ").
        append(StringUtils.quoteStringSQL(originalTable)).
        append(')');
    if (emitUpdates) {
        buff.append(" EMIT UPDATES");
    }
    if (readOnly) {
        buff.append(" READONLY");
    }
    buff.append(" /*" + JdbcSQLException.HIDE_SQL + "*/");
    return buff.toString();
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:36,代码来源:TableLink.java

示例13: testDatabaseFrom

import org.h2.jdbc.JdbcSQLException; //导入依赖的package包/类
@Test
public void testDatabaseFrom() {
    Database.from(DatabaseCreator.nextUrl(), 3) //
            .select("select name from person") //
            .getAs(String.class) //
            .count() //
            .test() //
            .awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
            .assertError(JdbcSQLException.class);
}
 
开发者ID:davidmoten,项目名称:rxjava2-jdbc,代码行数:11,代码来源:DatabaseTest.java

示例14: createSchema

import org.h2.jdbc.JdbcSQLException; //导入依赖的package包/类
private void createSchema() {
    try {
        con = this.dataSource.getConnection();
        pstm = con.prepareStatement("CREATE SCHEMA IF NOT EXISTS device_location");
        pstm.executeUpdate();
        System.out.println("Schema Created");
    } catch (JdbcSQLException e) {
        e.printStackTrace(System.out);
        System.out.println("Schema already exists");
    } catch (SQLException ex) {
        ex.printStackTrace(System.out);
        System.out.println("Schema ERROR");
    }

}
 
开发者ID:WiserUFBA,项目名称:wiser-services,代码行数:16,代码来源:BdBean.java

示例15: testDropNonExistingColumn

import org.h2.jdbc.JdbcSQLException; //导入依赖的package包/类
/**
 *
 * @throws Exception if failed.
 */
public void testDropNonExistingColumn() throws Exception {
    try {
        run("CREATE TABLE test (id INT PRIMARY KEY, a INT)");

        assertThrowsAnyCause("ALTER TABLE test DROP COLUMN b", JdbcSQLException.class, "Column \"B\" not found");
    }
    finally {
        run("DROP TABLE IF EXISTS test");
    }
}
 
开发者ID:apache,项目名称:ignite,代码行数:15,代码来源:H2DynamicColumnsAbstractBasicSelfTest.java


注:本文中的org.h2.jdbc.JdbcSQLException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。