Domino/Notes nhttp spikes on JDBC query to Informix - jdbc

When connecting to an Informix server via a Bean (or Jar - I've tried both) in an NSF, the nhttp task it spiking and staying spiked. I do not get this problem if the code is run in Eclipse. Here is what I trigger from an XPage (via a managed bean):
public void InformixSQLRS() {
try {
String url = "jdbc:informix-sqli://IPADDRESSHERE:PORTHERE/db_cra:INFORMIXSERVER=SERVERNAME;user=USERNAME;password=PASSWORD";
Class.forName("com.informix.jdbc.IfxDriver");
conn = DriverManager.getConnection(url);
System.out.println("After getting Driver");
String selectSQL = "SELECT FIRST 10 * FROM RtCSQsSummary ";
String whereSQL = "WHERE startdatetime >= TODAY ";
String orderbySQL = "ORDER BY startdatetime DESC";
String strsql = selectSQL + orderbySQL;
stmt = conn.createStatement();
System.out.println(strsql);
ResultSet rs = stmt.executeQuery(strsql);
System.out.println("after executeQuery");
ResultSetMetaData rsmd = rs.getMetaData();
int ncols = rsmd.getColumnCount();
int i, type;
String s = null;
for (i = 1; i < ncols; i++) {
System.out.println(
rsmd.getColumnLabel(i) + " " + rsmd.getColumnType(i));
}
stmt.close();
rs.close();
conn.close();
} catch (
SQLException e) {
System.out.println("ERROR: failed to connect!");
System.out.println("ERROR: " + e.getMessage());
e.printStackTrace();
return;
} catch (Exception e) {
System.out.println("Exception: " + e.getMessage());
} finally {
try {
if (rs != null) {
rs.close();
}
} catch (SQLException se) {
}
try {
if (stmt != null) {
stmt.close();
}
} catch (SQLException se) {
}
try {
if (conn != null) {
conn.close();
}
} catch (SQLException se) {
se.printStackTrace();
}
System.out.println("Goodbye! (finally)");
}
System.out.println("Last call");
}
I am on DDE Release 9.0.1FP10 SHF81. I have the Informix JDBC driver jdbc-4.10.8.1.jar. I have tried putting it in the Jars element, and importing to WebContent/WEB_INF/lib. This happens on both a Domino server Release 9.0.1FP9HF63 on Linux 2.6.32-696.13.2.el6.x86_64 and my local running Windows 7.
I get this error: Exception in thread "Informix-PreparedStatementCacheCleanupThread". Debugged in DDE and found that "IfxSqliConnectCleaner-Thread-1" was taking up a lot of CPU. Suspending that thread let the CPU count to return to normal.
The process completes, printing the results, and the strings at the end of finally and the block. Closing the browser does not release nhttp.
This matches samples provided to connect to Informix. I'm not sure what is causing it to spike/peg for Domino. Is there something I can do to get the thread to release?

Related

Does oracle physical connection impact performance while closing it

I am developing an application for my final year project, I need a quick clarification on java JDBC .. I am using Oracle physical connection(no connection pooling). When a user search in search criteria, the query execution is happening in 10 ms and returning the result set to UI is taking up to 1 minute. Code is been attached.
Connection con=null;
OracleConnection ocon = null;
ResultSet rs = null;
Gson gson = new Gson();
String gsonOrdrHeaderEntity="";
JSONObject searchObject = new JSONObject();
JSONObject returnSearchObject = new JSONObject();
CallableStatement callableStatement = null;
ArrayList<SearchEntity> searchArrayList = new ArrayList<>();
try{
con= DatasourceConfiguration.openConnection();
ocon = (OracleConnection)con.unwrap(OracleConnection.class);
callableStatement= con.prepareCall("call SEARCHPKG.QUERY(?,?,?,?,?)");
callableStatement.setString(1,entity.getSearch1());
callableStatement.setString(2,entity.getSearch2());
callableStatement.setString(3,entity.getSearch3());
callableStatement.setString(4,entity.getSearch4());
callableStatement.registerOutParameter(5, OracleTypes.CURSOR);
callableStatement.execute();
rs = ((OracleCallableStatement) callableStatement).getCursor(39);
if(rs != null)
while(rs.next()) {
OrderHeaderEntity searchEntity = new OrderHeaderEntity();
searchEntity.setSearch1(rs.getString(1));
searchEntity.setSearch2(rs.getString(3));
searchEntity.setSearch3(rs.getString(4));
searchEntity.setSearch4(rs.getString(5));
/**
* Description : Since there are will multiple order in a single search, we are adding the row to an array and iterating over it
*/
searchArrayList.add(searchEntity);
}
}catch(SQLException e){
logger.info("SQLException while performing search: "+e.getMessage());
throw e;
}catch(Exception e){
logger.info("Exception while performing search: "+e.getMessage());
}finally {
try {
if(rs != null) {rs.close();}
} catch (Exception e2) {
logger.info("Error while closing the search resultSet : "+e2.getMessage());
}
try {
if(callableStatement!=null) {callableStatement.close();}
} catch (Exception e2) {
logger.info("Error while closing the search callableStatment :"+e2.getMessage());
}
finally {
}
try {
if(con!=null) {con.close();}
} catch (Exception e2) {
logger.info("Error while the search connection :"+e2.getMessage());
}
}
}
/**
* #Description : mapping result set with JAVA object
*/
logger.info("Inside ProcedureCall >> search Proc>> converted to JSON successfully");
gsonOrdrHeaderEntity= gson.toJson(searchArrayList);
searchObject.put("order_header", gsonOrdrHeaderEntity);
returnSearchObject.put("status", "success");
returnSearchObject.put("message","Order Header Retrieved Successfully");
returnSearchObject.put("data", searchObject);
return returnSearchObject.toString();

stored procedure getting struck from java but working fine from SQL Developer

public void createCostRecord() throws Exception
{
Context ctx = null;
Connection conn = null;
CallableStatement ps = null;
ResultSet rs = null;
boolean spReturn = false;
try{
ctx = new InitialContext();
javax.sql.DataSource ds = (javax.sql.DataSource) ctx.lookup("CSMWebAppjndi");
conn = ds.getConnection();
conn.setAutoCommit(true);
String sp = "{call usp_CreateCostRecords(?,?)}";
ps = conn.prepareCall(sp);
ps.setInt(1, 1000);
ps.setInt(2, 2000);
for(int i=0;i<3;i++)
{
ps.executeQuery();
}
} catch (NamingException e)
{
log.error(e,e);
} catch (SQLException e)
{
log.error(e,e);
}
catch(Exception e)
{
log.error(e,e);
}
finally {
if(rs!=null){
rs.close();
}
if(ps!=null){
ps.close();
}
if(conn != null){
conn.close();
}
if(ctx != null ){
ctx.close();
}
}
}
while calling the above method the line number 23 executeQuery works fine for the first iteration of the for loop,
on second iteration of the for loop its getting struck at executeQuery and the procedure never completes execution.
But the weird thing is while i try the same procedure with same input from SQL developer its getting executed for any number of times without any struck.
Anyone help me to understand why the procedure from java is getting struck at second attempt and but its working fine in SQL developer.

jTable that will listen to jDateChooser's 'textfield'?

Hello everyone I'm trying to make a scheduling system for my System and Analysis Design thesis and I am having trouble trying to connect/bind/make the jTable listen to the jDateChooser's input. Elaborately, I want my scheduling to be like this:
I choose a date in the jDateChooser
jTable will 'sort out' itself via the date inputted on the jDatechooser
is there anyway to do this?
For now all I have is a table propertyChangelistener:
private void sched_tablePropertyChangeListener(java.beans.PropertyChangeEvent evt) {
try{
String calendar = ((JTextField)jdc.getDateEditor().getUiComponent()).getText();
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/accountsDB?zeroDateTimeBehavior=convertToNull","root","");
String query = "select * from accountsdb.schedules where Date= ?";
ps= conn.prepareStatement(query);
ps.setString(1, calendar);
ResultSet rs = ps.executeQuery();
sched_table.setModel(DbUtils.resultSetToTableModel(rs));
}
catch (Exception e){
JOptionPane.showMessageDialog(null, e);
} finally {
if (conn != null)
try { conn.close();
} catch (SQLException ignore) {}
if (ps != null){
try {
ps.close();
} catch (SQLException ignore){}
}
}
}
Somehow when I run my application it doesn't seem to open if that block of code is on it which means I really did do something wrong. Can anyone change or tell me what I should do or where should I start with the jTable listening to the jDatechooser thing?
~Thanks in advance for those who will answer!~
Nevermind, turns out all I had to do was change the jDateChooser's Date Format since it wasn't exactly the same formatting hence I couldn't call anything from the database. If anyone's interested on what I did I'll just leave this here
private void jdcPropertyChange(java.beans.PropertyChangeEvent evt) {
try{
String d1 = ((JTextField)jdc.getDateEditor().getUiComponent()).getText();
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/accountsDB?zeroDateTimeBehavior=convertToNull","root","");
String query = "select * from accountsdb.schedules where Date= ? order by time,timezone";
ps = conn.prepareStatement(query);
ps.setString(1, d1);
ResultSet rs = ps.executeQuery();
sched_table.setModel(DbUtils.resultSetToTableModel(rs));
} catch(Exception e){
JOptionPane.showMessageDialog(null, e);
} finally {
if (conn != null) {
try { conn.close();
} catch (SQLException ignore) {}
}
if (ps != null){
try {
ps.close();
} catch (SQLException ignore){}
}
}
}
What this does is that everytime I pick on a date from the jDateChooser(named it jdc) the table/database calls that date and sorts it out. Which is what I wanted.

how to use multiple queries in java using jdbc

how to use multiple queries in java using jdbc
1.how to use this below query in the method without deleting the already existing query in
method
Insert into item_details(stock_name,temple,quantity)
SELECT a.stock_name, a.temple, SUM(Case when Type='purchase' then quantity else
(quantity*-1) End) AS quantity
FROM purchase_details a
GROUP BY a.stock_name, a.temple
public boolean insertIntimationDetails(StockForm ofform) {
boolean status=false;
PreparedStatement pst=null;
Connection conn=null;
try {
System.out.println("Inside insertIntimationDetails ");
String query=" update purchase_details set intimation_quantity = ? where
temple=? and Stock_name=? ";
System.out.println(query);
conn=getConnection();
System.out.println(query);
pst=conn.prepareStatement(query);
System.out.println(ofform.getIntimationQuantity());
pst.setString(2, ofform.getForTemple());
pst.setString(3, ofform.getStockName());
pst.setLong(1, ofform.getIntimationQuantity());
int rows= pst.executeUpdate();
if(rows>0){
status=true;
}
} catch (Exception e) {
e.printStackTrace();
} finally{
try {
if(pst!=null)
pst.close();
if(conn!=null)
conn.close();
} catch (Exception e2) {
e2.printStackTrace();
}
}
return status;
}
You can make the two SQLs atomic by using something similar to below code. This guarantees all or nothing rule.
public boolean insertIntimationDetails(StockForm ofform) {
boolean status = false;
PreparedStatement pst = null;
Connection conn = null;
Statement stat = null;
try {
System.out.println("Inside insertIntimationDetails ");
String query = " update purchase_details set intimation_quantity = ? where temple=? and Stock_name=? ";
System.out.println(query);
conn = getConnection();
conn.setAutoCommit(false); // Disable Auto Commit
System.out.println(query);
pst = conn.prepareStatement(query);
System.out.println(ofform.getIntimationQuantity());
pst.setString(2, ofform.getForTemple());
pst.setString(3, ofform.getStockName());
pst.setLong(1, ofform.getIntimationQuantity());
int rows = pst.executeUpdate();
if (rows > 0) {
status = true;
}
stat = conn.createStatement();
boolean status2 = stat
.execute("Insert into item_details(stock_name,temple,quantity) SELECT a.stock_name, a.temple, SUM(Case when Type='purchase' then quantity else (quantity*-1) End) AS quantity FROM purchase_details a GROUP BY a.stock_name, a.temple");
if (status && status2) {
conn.commit();
} else {
conn.rollback();
}
} catch (Exception e) {
e.printStackTrace();
conn.rollback();
} finally {
try {
if (pst != null)
pst.close();
if (stat != null)
stat.close();
if (conn != null)
conn.close();
} catch (Exception e2) {
e2.printStackTrace();
}
}
return status;
}

How to fix error thrown during update of scroll sensitive resultset?

I'm trying to update a row in ResultSet, but it is throwing an error. I passed the constant value ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE to createStatement.
this is my code :
public void modifyPrice(float percentage) throws SQLException {
try {
con = util.connectdb();
con.setAutoCommit(false);
st = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
ResultSet rs = st.executeQuery("select * from " + util.dbName
+ ".COFFEES");
while (rs.next()) {
float f = rs.getFloat("PRICE");
rs.updateFloat("PRICE", f * percentage);
rs.updateRow();
}
} catch (SQLException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} finally {
if (st != null) {
st.close();
con.close();
}
}
}
When I executed this code block, the stack below got printed on console.
java.sql.SQLException: Invalid operation for read only resultset: updateFloat
at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:70)
at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:131)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:197)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:261)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:269)
at oracle.jdbc.driver.BaseResultSet.updateFloat(BaseResultSet.java:236)
at oracle.jdbc.driver.OracleResultSet.updateFloat(OracleResultSet.java:677)
at tutorial.ModifyResultSet.modifyPrice(ModifyResultSet.java:29)
at tutorial.ModifyResultSet.main(ModifyResultSet.java:15)
Can anyone help me fix this error?
According to these links
http://www.coderanch.com/t/301466/JDBC/databases/Invalid-operation-read-only-resultset
http://www.coderanch.com/t/295932/JDBC/databases/updateXXX-function-ResultSet
instead of "select * from" you should use "select my_column_name from" statement.
See if it makes any difference.

Resources