當前位置: 首頁>>代碼示例>>Java>>正文


Java SQLException類代碼示例

本文整理匯總了Java中java.sql.SQLException的典型用法代碼示例。如果您正苦於以下問題:Java SQLException類的具體用法?Java SQLException怎麽用?Java SQLException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


SQLException類屬於java.sql包,在下文中一共展示了SQLException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createDatabase

import java.sql.SQLException; //導入依賴的package包/類
private static void createDatabase() throws SQLException {

        new File("testdb.backup").delete();
        new File("testdb.data").delete();
        new File("testdb.properties").delete();
        new File("testdb.script").delete();

        Connection con = DriverManager.getConnection("jdbc:hsqldb:testdb",
            "sa", "");
        String[] saDDL = {
            "CREATE CACHED TABLE XB (EIACODXA VARCHAR(10) NOT NULL, LSACONXB VARCHAR(18) NOT NULL, ALTLCNXB VARCHAR(2) NOT NULL, LCNTYPXB VARCHAR(1) NOT NULL, LCNINDXB VARCHAR(1), LCNAMEXB VARCHAR(19), UPDT_BY VARCHAR(32), LST_UPDT TIMESTAMP, CONSTRAINT XPKXB PRIMARY KEY (EIACODXA, LSACONXB, ALTLCNXB, LCNTYPXB));",
            "CREATE INDEX XIF2XB ON XB (EIACODXA);",
            "CREATE CACHED TABLE CA ( EIACODXA VARCHAR(10) NOT NULL, LSACONXB VARCHAR(18) NOT NULL, ALTLCNXB VARCHAR(2) NOT NULL, LCNTYPXB VARCHAR(1) NOT NULL, TASKCDCA VARCHAR(7) NOT NULL, TSKFRQCA NUMERIC(7,4), UPDT_BY VARCHAR(32), LST_UPDT TIMESTAMP, CONSTRAINT XPKCA PRIMARY KEY (EIACODXA, LSACONXB, ALTLCNXB, LCNTYPXB, TASKCDCA),        CONSTRAINT R_XB_CA FOREIGN KEY (EIACODXA, LSACONXB, ALTLCNXB, LCNTYPXB) REFERENCES XB ON DELETE CASCADE);",
            "CREATE INDEX XIF26CA ON CA ( EIACODXA, LSACONXB, ALTLCNXB, LCNTYPXB);"
        };
        Statement stmt = con.createStatement();

        for (int index = 0; index < saDDL.length; index++) {
            stmt.executeUpdate(saDDL[index]);
        }

        con.close();
    }
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:24,代碼來源:TestCascade.java

示例2: setClientInfo

import java.sql.SQLException; //導入依賴的package包/類
public synchronized void setClientInfo(java.sql.Connection conn, Properties properties) throws SQLClientInfoException {
    try {
        Enumeration<?> propNames = properties.propertyNames();

        while (propNames.hasMoreElements()) {
            String name = (String) propNames.nextElement();
            String value = properties.getProperty(name);

            setClientInfo(conn, name, value);
        }
    } catch (SQLException sqlEx) {
        SQLClientInfoException clientInfoEx = new SQLClientInfoException();
        clientInfoEx.initCause(sqlEx);

        throw clientInfoEx;
    }
}
 
開發者ID:bragex,項目名稱:the-vigilantes,代碼行數:18,代碼來源:JDBC4ClientInfoProviderSP.java

示例3: updateInt

import java.sql.SQLException; //導入依賴的package包/類
@Override
public void updateInt(String columnLabel, int x) throws SQLException {
    throw new UnsupportedOperationException("Not supported yet.");
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:5,代碼來源:StubSyncResolver.java

示例4: checkParameterBounds

import java.sql.SQLException; //導入依賴的package包/類
protected synchronized void checkParameterBounds(int parameterIndex) throws SQLException
{
    checkClosed();
    if ((parameterIndex < 1) || (parameterIndex > this.Query.getParameterCount())) {
        throw SQLError.get(SQLError.PARAMETER_NOT_FOUND, parameterIndex, this.Query.getParameterCount());
    }
}
 
開發者ID:s-store,項目名稱:s-store,代碼行數:8,代碼來源:JDBC4PreparedStatement.java

示例5: setClientInfo

import java.sql.SQLException; //導入依賴的package包/類
public void setClientInfo(Properties properties) throws SQLClientInfoException {
    try {
        getClientInfoProviderImpl().setClientInfo(this, properties);
    } catch (SQLClientInfoException ciEx) {
        throw ciEx;
    } catch (SQLException sqlEx) {
        SQLClientInfoException clientInfoEx = new SQLClientInfoException();
        clientInfoEx.initCause(sqlEx);

        throw clientInfoEx;
    }
}
 
開發者ID:rafallis,項目名稱:BibliotecaPS,代碼行數:13,代碼來源:JDBC4Connection.java

示例6: initializeJiraDataBaseForImport

import java.sql.SQLException; //導入依賴的package包/類
/**
 * Initialize data base with 'MDA' JIRA project.
 */
@BeforeClass
public static void initializeJiraDataBaseForImport() throws SQLException {
	datasource = new SimpleDriverDataSource(new JDBCDriver(), "jdbc:hsqldb:mem:dataSource", null, null);
	final Connection connection = datasource.getConnection();
	try {
		ScriptUtils.executeSqlScript(connection,
				new EncodedResource(new ClassPathResource("sql/base-1/jira-create.sql"), StandardCharsets.UTF_8));
		ScriptUtils.executeSqlScript(connection,
				new EncodedResource(new ClassPathResource("sql/base-2/jira-create.sql"), StandardCharsets.UTF_8));
		ScriptUtils.executeSqlScript(connection,
				new EncodedResource(new ClassPathResource("sql/upload/jira-create.sql"), StandardCharsets.UTF_8));

		ScriptUtils.executeSqlScript(connection, new EncodedResource(new ClassPathResource("sql/base-1/jira.sql"), StandardCharsets.UTF_8));
		ScriptUtils.executeSqlScript(connection, new EncodedResource(new ClassPathResource("sql/base-2/jira.sql"), StandardCharsets.UTF_8));
		ScriptUtils.executeSqlScript(connection, new EncodedResource(new ClassPathResource("sql/upload/jira.sql"), StandardCharsets.UTF_8));
	} finally {
		connection.close();
	}
}
 
開發者ID:ligoj,項目名稱:plugin-bt-jira,代碼行數:23,代碼來源:JiraUpdateDaoTest.java

示例7: deleteProductoPresupuesto

import java.sql.SQLException; //導入依賴的package包/類
public static void deleteProductoPresupuesto(String id, String producto_id, String producto_unidad_medida_id, String proyecto_id, String proyecto_subprograma_id, String proyecto_subprograma_programa_id, String proyecto_subprograma_programa_tipo_presupuesto_id, String proyecto_subprograma_programa_entidad_id, String proyecto_subprograma_programa_entidad_nivel_id){
 	 Connection conect=ConnectionConfiguration.conectar();
 	 Statement statement = null;
 String 														query = "delete from producto_presupusto ";
 //if (id!="")													query+= "id=\""+id+"\", ";
 /*if (numero_fila!="")											query+= "numero_fila=\""+numero_fila+"\", ";
 if (anho!="")													query+= "anho=\""+anho+"\", ";
 //if (producto_id!="")											query+= "producto_id=\""+producto_id+"\", ";
 //if (producto_unidad_medida_id!="")							query+= "producto_unidad_medida_id=\""+producto_unidad_medida_id+"\", ";
 //if (proyecto_id!="")											query+= "proyecto_id=\""+proyecto_id+"\", ";
 //if (proyecto_subprograma_id!="")								query+= "proyecto_subprograma_id=\""+proyecto_subprograma_id+"\", ";
 //if (proyecto_subprograma_programa_id!="")					query+= "proyecto_subprograma_programa_id=\""+proyecto_subprograma_programa_id+"\", ";
 //if (proyecto_subprograma_programa_tipo_presupuesto_id!="")	query+= "proyecto_subprograma_programa_tipo_presupuesto_id=\""+proyecto_subprograma_programa_tipo_presupuesto_id+"\", ";
 //if (proyecto_subprograma_programa_entidad_id!="")			query+= "proyecto_subprograma_programa_entidad_id=\""+proyecto_subprograma_programa_entidad_id+"\", ";
 //if (proyecto_subprograma_programa_entidad_nivel_id!="")		query+= "proyecto_subprograma_programa_entidad_nivel_id=\""+proyecto_subprograma_programa_entidad_nivel_id+"\", ";
 if (version!="")			query+= "version=\""+version+"\", ";
 query = query.substring(0, query.length()-2);*/
 query+="where id="+id+" and producto_id="+producto_id+" and producto_unidad_medida_id="+producto_unidad_medida_id+" and proyecto_id="+proyecto_id+" and proyecto_subprograma_id="+proyecto_subprograma_id+" and proyecto_subprograma_programa_id="+proyecto_subprograma_programa_id+" and proyecto_subprograma_programa_tipo_presupuesto_id="+proyecto_subprograma_programa_tipo_presupuesto_id+" and proyecto_subprograma_programa_entidad_id="+proyecto_subprograma_programa_entidad_id+" and proyecto_subprograma_programa_entidad_nivel_id="+proyecto_subprograma_programa_entidad_nivel_id;
		
try {
	statement=conect.createStatement();
	statement.execute(query);
    conect.close();
} catch (SQLException e) {e.printStackTrace();}
 }
 
開發者ID:stppy,項目名稱:spr,代碼行數:26,代碼來源:SqlDelete.java

示例8: setClientInfo

import java.sql.SQLException; //導入依賴的package包/類
public void setClientInfo(String name, String value) throws SQLClientInfoException {
    try {
        checkClosed();

        ((java.sql.Connection) this.mc).setClientInfo(name, value);
    } catch (SQLException sqlException) {
        try {
            checkAndFireConnectionError(sqlException);
        } catch (SQLException sqlEx2) {
            SQLClientInfoException clientEx = new SQLClientInfoException();
            clientEx.initCause(sqlEx2);

            throw clientEx;
        }
    }
}
 
開發者ID:rafallis,項目名稱:BibliotecaPS,代碼行數:17,代碼來源:JDBC4ConnectionWrapper.java

示例9: setCharacterStream

import java.sql.SQLException; //導入依賴的package包/類
public void setCharacterStream(String parameterName, Reader reader, int length) throws SQLException {
    try {
        if (this.wrappedStmt != null) {
            ((CallableStatement) this.wrappedStmt).setCharacterStream(parameterName, reader, length);
        } else {
            throw SQLError.createSQLException("No operations allowed after statement closed", SQLError.SQL_STATE_GENERAL_ERROR, this.exceptionInterceptor);
        }
    } catch (SQLException sqlEx) {
        checkAndFireConnectionError(sqlEx);
    }
}
 
開發者ID:bragex,項目名稱:the-vigilantes,代碼行數:12,代碼來源:CallableStatementWrapper.java

示例10: getTables

import java.sql.SQLException; //導入依賴的package包/類
/**
 * Gets tables.
 *
 * @param connection the connection
 * @param keys keys
 * @param tablesOverride the tables override @return the tables
 * @throws SQLException the sql exception
 */
public Map<String, Map<String, Object>> getTables(Connection connection, String keys,
                                                  Map<String, Map<String, Object>> tablesOverride) throws SQLException {
    Map<String, Map<String, Object>> dataMap = new HashMap<>(16);
    DatabaseMetaData metaData = connection.getMetaData();
    // 處理key列表
    List<String> keyList = new ArrayList<>(1);
    if (keys != null) {
        String[] keyArray = keys.split(",");
        keyList = Arrays.asList(keyArray);
    } else {
        keyList.add("%");
    }
    // 根據key列表抽取指定表
    for (String key : keyList) {
        ResultSet resultSet = metaData.getTables(null, null, key, null);
        while (resultSet.next()) {
            Map<String, Object> table = new HashMap<>(4);
            String tableName = resultSet.getString(TABLE_NAME);
            LOGGER.info("抽取表結構>>{}", tableName);
            // 獲取主鍵
            ResultSet primaryKeys = metaData.getPrimaryKeys(null, null, tableName);
            if (primaryKeys.next()) {
                String primaryColumn = primaryKeys.getString(COLUMN_NAME);
                table.put("primaryColumn", primaryColumn);
                table.put("primaryName", StringUtils.getCamelCaseString(primaryColumn, false));
                table.put("primaryAuto", false);
            } else {
                LOGGER.warn("獲取表{}主鍵失敗,跳過該表", tableName);
                continue;
            }
            table.put("tableName", tableName);
            table.put("comment", resultSet.getString(REMARKS));
            String className = StringUtils.getCamelCaseString(tableName, true);
            table.put("className", className);

            table.put("imports", new HashSet<>(5));

            // 使用配置文件進行覆蓋
            Map<String, Object> tableOverride = tablesOverride.get(tableName);
            Map<String, Map<String, Object>> columnsOverride = new HashMap<>(0);
            if (tableOverride != null) {
                table.putAll(tableOverride);
                table.remove("columns");
                List<Map<String, Object>> columnsOverrideList = (List<Map<String, Object>>) tableOverride.get("columns");
                if (columnsOverrideList != null) {
                    columnsOverride = columnsOverrideList.stream().collect(Collectors.toMap(o -> (String) o.get("columnName"),
                                                                                            o -> o));
                }
            }
            List<Map<String, Object>> columns = getColumns(connection, table, columnsOverride);
            table.put("columns", columns);
            dataMap.put(tableName, table);
        }
    }
    return dataMap;
}
 
開發者ID:sgota,項目名稱:tkcg,代碼行數:65,代碼來源:DbDataMapHelper.java

示例11: stop

import java.sql.SQLException; //導入依賴的package包/類
@Override
public void stop() {
    if(connection != null) {
        try {
            connection.close();
        } catch (SQLException ex) {
            
        }
        connection = null;
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:12,代碼來源:CustomJDBCConnectionProvider.java

示例12: supportsStoredProcedures

import java.sql.SQLException; //導入依賴的package包/類
/**
* Are stored procedure calls using the stored procedure escape
* syntax supported?
* @return <code>true</code> if so
* @exception SQLException if a database access error occurs
*/
public boolean supportsStoredProcedures() throws SQLException
{
    Boolean storedProcedures = (Boolean)properties.get(PROP_STORED_PROCEDURES);
    if (storedProcedures == null) {
        if (dmd != null) storedProcedures = dmd.supportsStoredProcedures() ? Boolean.TRUE : Boolean.FALSE;
        else throw new SQLException(bundle.getString("EXC_NoDBMetadata")); // NOI18N
        properties.put(PROP_STORED_PROCEDURES, storedProcedures);
    }

    return storedProcedures.booleanValue();
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:18,代碼來源:DefaultAdaptor.java

示例13: queryEntityList

import java.sql.SQLException; //導入依賴的package包/類
/**
 * 查詢對應的實體列表,返回多條記錄
 */
public <T> List<T> queryEntityList(Class<T> entityClass, String sql, Object... params) {
    List<T> result;
    try {
    	result = queryRunner.query(sql, new BeanListHandler<T>(entityClass), params);
    } catch (SQLException e) {
        logger.error("查詢出錯!");
        throw new RuntimeException(e);
    }
    printSQL(sql);
    return result;
}
 
開發者ID:smxc,項目名稱:garlicts,代碼行數:15,代碼來源:JdbcTemplate.java

示例14: testBug46637

import java.sql.SQLException; //導入依賴的package包/類
public void testBug46637() throws Exception {
    String hostname = getPortFreeHostname(null, new NonRegisteringDriver());
    UnreliableSocketFactory.flushAllStaticData();
    UnreliableSocketFactory.downHost(hostname);

    try {
        Connection noConn = getConnectionWithProps("socketFactory=testsuite.UnreliableSocketFactory");
        noConn.close();
    } catch (SQLException sqlEx) {
        assertTrue(sqlEx.getMessage().indexOf("has not received") != -1);
    } finally {
        UnreliableSocketFactory.flushAllStaticData();
    }
}
 
開發者ID:bragex,項目名稱:the-vigilantes,代碼行數:15,代碼來源:ConnectionRegressionTest.java

示例15: checkGetParameterIndex

import java.sql.SQLException; //導入依賴的package包/類
/**
 * Checks if the specified parameter index value is valid in terms of
 * getting an OUT or INOUT parameter value. <p>
 *
 * @param i The parameter index to check
 * @throws SQLException if the specified parameter index is invalid
 */
protected void checkGetParameterIndex(int i) throws SQLException {

    String msg;

    checkClosed();

    if (i < 1 || i > parameterValues.length) {
        msg = "parameter index out of range: " + i;

        throw Util.outOfRangeArgument(msg);
    }

    int mode = parameterModes[i - 1];

    switch (mode) {

        case SchemaObject.ParameterModes.PARAM_UNKNOWN :
        case SchemaObject.ParameterModes.PARAM_OUT :
        case SchemaObject.ParameterModes.PARAM_INOUT :
            break;
        case SchemaObject.ParameterModes.PARAM_IN :
        default :
            msg = "Not OUT or INOUT mode: " + mode + " for parameter: "
                  + i;

            throw Util.invalidArgument(msg);
    }
}
 
開發者ID:s-store,項目名稱:s-store,代碼行數:36,代碼來源:JDBCPreparedStatement.java


注:本文中的java.sql.SQLException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。