本文整理汇总了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();
}
示例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;
}
}
示例3: updateInt
import java.sql.SQLException; //导入依赖的package包/类
@Override
public void updateInt(String columnLabel, int x) throws SQLException {
throw new UnsupportedOperationException("Not supported yet.");
}
示例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());
}
}
示例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;
}
}
示例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();
}
}
示例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();}
}
示例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;
}
}
}
示例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);
}
}
示例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;
}
示例11: stop
import java.sql.SQLException; //导入依赖的package包/类
@Override
public void stop() {
if(connection != null) {
try {
connection.close();
} catch (SQLException ex) {
}
connection = null;
}
}
示例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();
}
示例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;
}
示例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();
}
}
示例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);
}
}