Oracle OCI jdbc driver traps ORA-01403: no data found - oracle

I'm having a problem with the Oracle OCI jdbc driver not throwing ORA-01403 No data found exceptions. Relevant to Oracle 11 and 12. Maybe there is a property or something I need to set on the Connection object. The thin driver properly throws an exception, but the OCI driver just continues on with no error and updates 0 rows even though there is data in the table.
The output of the following program is:
Exception thrown from THIN Driver: ORA-01403: no data found
ORA-06512: at "EE.TABLEX_UPSERT_PRE", line 4
ORA-04088: error during execution of trigger 'EE.TABLEX_UPSERT_PRE'
rows updated from OCI Driver =0
public static void main(String[] args) {
try {
Driver d = (Driver) Class.forName("oracle.jdbc.OracleDriver").newInstance();
Properties info = new Properties();
info.put("user", "me");
info.put("password", "mypwd");
Connection thinConnection = d.connect("jdbc:oracle:thin:#host:1521:DEV",info);
Connection ociConnection = d.connect("jdbc:oracle:oci:#DEV",info);
try {
Statement s = thinConnection.createStatement();
s.execute("UPDATE tablex SET name='newname'");
System.out.println("rows updated in THIN Driver =" + s.getUpdateCount());
}
catch (SQLException e) {
System.out.println("Exception thrown from THIN Driver: " + e.getMessage());
}
try {
Statement s = ociConnection.createStatement();
s.execute("UPDATE tablex SET name='newname'");
System.out.println("rows updated from OCI Driver =" + s.getUpdateCount());
}
catch (SQLException e) {
System.out.println("Exception thrown from OCI Driver: " + e.getMessage());
}
}
catch (Exception e) {
e.printStackTrace();
}
System.exit(0);
}
{////// SQL
CREATE TABLE TABLEX
(
NAME VARCHAR2(20)
);
INSERT INTO TABLEX(name) values('data1');
CREATE TABLE TABLEy
(
ID NUMBER
);
create or replace
TRIGGER TABLEX_UPSERT_PRE
BEFORE INSERT OR UPDATE ON TABLEX FOR EACH ROW
DECLARE
cid number;
BEGIN
select id into cid from tabley where id=0; -- INTENTIONAL No Data Found error
end;
}

Related

MariaDB Connector J : autoReconnect does not wok for Basic Faillover

From https://mariadb.com/kb/en/library/about-mariadb-connector-j/, for option autoReconnect, When this parameter enabled when a Failover and Load Balancing Mode is not in use, the connector will simply try to reconnect to its host after a failure. This is referred to as Basic Failover.
But the problem is that the reconnect does not work after server failure. The test code is as follows:
#Test
public void waitTimeoutResultSetTest() throws SQLException, InterruptedException {
try (Connection connection = setBlankConnection("&autoReconnect=true")) {
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("SELECT 1");
assertTrue(rs.next());
stmt.execute("set session wait_timeout=1");
Thread.sleep(3000); // Wait for the server to kill the connection
try {
rs = stmt.executeQuery("show databases;");
assertTrue(rs.next());
System.out.println("position 1");
} catch (SQLException e) {
//normal exception
System.out.println("position 2");
}
}
}
With autoReconnect, I think the expected result is that it will get to position 1, but actually it will get to position 2, with exception that "Connection reset by peer: socket write error."
My question is that whether the basic failover does not work, or my test code is wrong? I cannot find other information from web, could you kindly give me some explanation if you know about it?

Spring JDBC Template - Maximum open cursors exceeded

Our application connects to Oracle database and we use JDBCTemplate provided by Spring to interact with the database. As per the documentation of Spring JDBCTemplate, it ensures that it will close all the connections and cursors. But apparently we are get the following open cursors exception.
ORA-01000: maximum open cursors exceeded at
org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:84)
~[spring-jdbc-4.2.6.RELEASE.jar!/:4.2.6.RELEASE] at
org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
~[spring-jdbc-4.2.6.RELEASE.jar!/:4.2.6.RELEASE] at
org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
~[spring-jdbc-4.2.6.RELEASE.jar!/:4.2.6.RELEASE] at
org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:645)
~[spring-jdbc-4.2.6.RELEASE.jar!/:4.2.6.RELEASE] at
org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:680)
~[spring-jdbc-4.2.6.RELEASE.jar!/:4.2.6.RELEASE] at
org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:712)
~[spring-jdbc-4.2.6.RELEASE.jar!/:4.2.6.RELEASE] at
org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:722)
~[spring-jdbc-4.2.6.RELEASE.jar!/:4.2.6.RELEASE] at
org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:790)
~[spring-jdbc-4.2.6.RELEASE.jar!/:4.2.6.RELEASE] at
org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:809)
~[spring-jdbc-4.2.6.RELEASE.jar!/:4.2.6.RELEASE]
The snippet:
private Optional<PartyAccess> executeQuery(Object... args) {
try {
String query = "SELECT EMP.ID as PARTY_ID, EMP.MPIN_HSB, EMP.INVALID_MPIN_HSB_COUNT, " +
"EMP.MPIN_HSB_MODIFIED_ON, EMP.MPIN_LSB, EMP.INVALID_MPIN_LSB_COUNT, EMP.MPIN_LSB_MODIFIED_ON, " +
"EMP.EMP_PIN AS SMS_PIN, EMP.NUMBER_OF_PIN_CODE_FAILURE AS INVALID_SMS_PIN_COUNT, EMP.PIN_MODIFIED_ON, " +
"EMP.PINFLAG AS USE_SHA2_HASH_FOR_PIN, CASE WHEN EMP_BLACKLIST_STATUS = 'Y' THEN 1 ELSE 0 END AS BLOCKED " +
"FROM MTX_EMPLOYEE EMP WHERE EMP.ID = ?";
return Optional.of((PartyAccess) jdbcTemplate.queryForObject(query,
args,
new BeanPropertyRowMapper(PartyAccess.class)));
} catch (DataAccessException ex) {
LOGGER.error("Error occurred", ex);
return Optional.empty();
}
}
We use hikari for JDBC connection pool and the maximum size if 10. We are facing the issue when there are lot of requests coming to the application. I tried increasing the max_cursors of database (bad solution, I know). But even, that didn't help. We monitored the open cursors when there are lot of requests coming in, the value didn't exceed the max cursor value which is being set.
The issue got fixed, after upgrading the JPA version to latest. The earlier spring jpa version was not closing the cursors properly.

updating a record at runtime using jdbc

I have problem updating my password at runtime.
It gives no error but it just doesn't work.
Please help .
Thanks in Advance!
Here is my code:
//HERE IS THE PROBLEM PART WHICH IS NOT WORKING
try {
System.out.println("id is : "+j);
System.out.println("What do you want your new password to be?");
Scanner s8=new Scanner(System.in);
String s7=s8.nextLine();
Class.forName("com.mysql.jdbc.Driver");
Connection con5=DriverManager.getConnection("jdbc:mysql://localhost:3306/login","root","q");
PreparedStatement ps=con5.prepareStatement("update pass set password=? where id=?");
ps.setString(1,s7);
ps.setInt(2,j);
}
catch(Exception e)
{
System.out.println(e);
}
You miss the execution of your statement using PreparedStatement.executeUpdate().
From javadoc
Executes the SQL statement in this PreparedStatement object, which
must be an SQL Data Manipulation Language (DML) statement, such as
INSERT, UPDATE or DELETE; or an SQL statement that returns nothing,
such as a DDL statement.

Oracle MAF Error "Unable to read DataControl Usages, on loadDataControl for id:"

I have created a simple SOAP web service for a remote DB which is working fine in WebLogic 12c server and also in Jdeveloper HTTP analyzer. When I am using the same web service in the code below, I am getting the following error (I have included the System.out.println outputs in ref. to the flow of the code) I am using Jdeveloper 12C MAF 2.0.0.0.41 on Mac OSx 10.9.
Chk #0
Processing row# 1
Chk #1
Chk #2
[SEVERE - oracle.adfmf.framework - AmxBindingContext - loadDataControlById] Unable to read DataControl Usages, on loadDataControl for id: WLFNewActWS.
[SEVERE - oracle.adfmf.framework - SynchronizationDC - syncDataFromOfflineToOnline] [Ljava.lang.StackTraceElement;#467c53d3
public void syncDataFromOfflineToOnline() {
Trace.log(Utility.FrameworkLogger, Level.INFO, this.getClass(), "syncDataFromOfflineToOnline",
"Executing syncDataFromOfflineToOnline Method");
try {
Connection conn = DBConnectionFactory.getConnection();
conn.setAutoCommit(false);
String select = "SELECT * FROM DEPARTMENTS";
PreparedStatement pStmt = conn.prepareStatement(select);
ResultSet rs = pStmt.executeQuery();
System.out.println("Chk #0");
int rowcount = 0;
while (rs.next()) {
rowcount++;
System.out.println("Processing row# " + rowcount);
List namesList = new ArrayList(1);
List paramsList = new ArrayList(1);
List typesList = new ArrayList(1);
Department dept = new Department();
dept.setDeptId(rs.getInt("DEPARTMENT_ID"));
dept.setDeptName(rs.getString("DEPARTMENT_NAME"));
dept.setMgrId(rs.getInt("MANAGER_ID"));
dept.setLocId(rs.getInt("LOCATION_ID"));
System.out.println("Chk #1");
GenericType gtDept =
GenericTypeBeanSerializationHelper.toGenericType("WLFNewActWS.Types.persistDepartments.arg0", dept);
System.out.println("Chk #2");
namesList.add("arg0");
paramsList.add(gtDept);
typesList.add(GenericType.class);
AdfmfJavaUtilities.invokeDataControlMethod("WLFNewActWS", null, "persistDepartments", namesList,
paramsList, typesList);
System.out.println("Chk #3");
}
} catch (SQLException e) {
Trace.log(Utility.FrameworkLogger, Level.SEVERE, this.getClass(), "syncDataFromOfflineToOnline",
e.getMessage());
} catch (Exception e) {
Trace.log(Utility.FrameworkLogger, Level.SEVERE, this.getClass(), "syncDataFromOfflineToOnline",
e.getStackTrace());
}
}
This may not be the answer to this question, but it may be the answer for someone searching for "Unable to read DataControl Usages, on loadDataControl for id"
In my case it is with Oracle MAF, but this also applies to Oracle ADF.
Your web service needs to be in your DataBindings.cpx file.
Something like:
<dataControlUsages>
<dc id="WLFNewActWS " path="mobile.WLFNewActWS "/>
</dataControlUsages>
I cheat and drag something from the WS into a one of pages and have jdeveloper add the record in DataBindings.cpx for me.
This occurs of the binding issue. Please create a reference/binding to 'WLFNewActWS' in your amx page. It will solve your problem...!

How to close refcursor in spring when using simplejdbccall

I am using spring simpleJdbcCall to call oracle stored procedure and i am using oracle 11g .
I stumbled on a couple of posts which suggests there might be memory leak as the ref cursors are not properly closed by spring.
Is there anyway to explicitly close cursor while using spring simplejdbccall? or is increasing the oracle OPEN_CURSOR the only way out?.
I am planning to scale up my application to handle around one million transactions every hour .Any suggestions will be helpful.
Actually there is no such an issue with Spring JDBC. It closes all resources within finally after all execute. SimpleJdbcCall uses JdbcTemplate:
public <T> T execute(CallableStatementCreator csc, CallableStatementCallback<T> action)
throws DataAccessException {
try {
...
}
catch (SQLException ex) {
...
}
finally {
if (csc instanceof ParameterDisposer) {
((ParameterDisposer) csc).cleanupParameters();
}
JdbcUtils.closeStatement(cs);
DataSourceUtils.releaseConnection(con, getDataSource());
}
}
The same for ResultSet OUT parameters:
protected Map<String, Object> processResultSet(ResultSet rs, ResultSetSupportingSqlParameter param) throws SQLException {
....
finally {
JdbcUtils.closeResultSet(rs);
}
return returnedResults;
}
From other side I have a big experience with Spring JDBC and Oracle in high-loaded systems and want to say that we noticed enough open resources on Oracle with at peak loads, but they have been released properly after that.
Although we used JBOSS Pooled DataSource and its TransactionMaanger
I use CallableStatement directly and I can release statements and connections quickly and safely, try both methods and measure memory consumption, it worked perfectly for me to solve memory consumption and connection retention problems that proved many waiting and rejection of connections the applications.
try {
log.info("**** RepositoryPSostgres.getAllProducts ******** ");
Connection conn = jdbcTemplate.getDataSource().getConnection();
conn.setAutoCommit(false);
// Procedure call.
CallableStatement proc = conn.prepareCall("{? = call get_all_products() }");
proc.registerOutParameter(1, Types.OTHER);
proc.execute();
ResultSet results = (ResultSet) proc.getObject(1);
**proc.close();
proc.isClosed();
conn.close();**
ArrayList <Products> resp = new ArrayList <Products>();
while (results.next()) {
Products resp1 = new Products();
resp1.setId(results.getInt("id"));
resp1.setName((String) results.getString("name"));
resp1.setPrice((BigDecimal) results.getBigDecimal("price"));
resp.add(resp1);
log.info("***" + results.getInt("id") + "***** ");
log.info("***" + results.getString("name") + "***** ");
log.info("***" + results.getBigDecimal("price") + "***** ");
}
results.close();
return resp;
} catch (Exception e) {
e.printStackTrace();
log.error(new StringBuffer("Error en transaccion en saldo CashPooling : ").append(e.getLocalizedMessage()).toString());
return null;
}

Resources