on 06-15-2009 7:11 PM
I am having strange issue with Webdynpro application running JDBC code. Webdynpro application hangs intermittently when it tries to run the below jdbc code .
This code is written on custom controller. We are using the SAPSR3DB datasource. Do anybody have any idea why this is happening . Thanks in advance
wdThis.wdGetAPI().getComponent().getMessageManager();
try {
Connection conn;
InitialContext ctx = new InitialContext();
DataSource dataSource = (DataSource) ctx.lookup(readPropertyFile());
conn = dataSource.getConnection();
PreparedStatement stmt =
conn.prepareStatement(
"insert into ZAE_PROD_GRtable(AUFNR,EXIDV_P,EXIDV_C,MATNR,WERKS,CHARG,VEMNG,VEMEH,CWMVEMNG,CWMVEMEH,STATUS,INDC) values(?,?,?,?,?,?,?,?,?,?,?,?)");
stmt.setString(1, wdContext.currentContextElement().getAUFNR());
stmt.setString(2, wdContext.currentHUDataElement().getEXIDVP());
stmt.setString(3, wdContext.currentHUDataElement().getEXIDVC());
stmt.setString(4, wdContext.currentOrderDataElement().getMATNR());
stmt.setString(5, wdContext.currentOrderDataElement().getWERKS());
stmt.setString(6, wdContext.currentOrderDataElement().getBATCH());
stmt.setString(7, wdContext.currentHUDataElement().getVEMNGP());
stmt.setString(8, wdContext.currentHUDataElement().getVEMEHP());
stmt.setString(9, wdContext.currentHUDataElement().getVEMNGC());
stmt.setString(10, wdContext.currentHUDataElement().getVEMEHC());
stmt.setString(11, "1");
stmt.setString(12, wdContext.currentContextElement().getHuIndicator));
stmt.executeUpdate();
stmt.close();
conn.close();
} catch (SQLException ex) {
msgMgr.reportException(ex.getLocalizedMessage() +";SQL State - " + ex.getSQLState(), true);
} catch (Exception ex) {
msgMgr.reportException(ex.getLocalizedMessage(), true);
finally {
try {
conn.close();
} catch (Exception e) {
msgMgr.reportException(e.getLocalizedMessage(),true);
}
}
}
Hi,
Please try to split the entire code into parts and try to debug part by part.
Check if the connection is working fine. Check if you are able to fetch data.
Debug and try to find out the solution
AM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello,
There can be any issue, i dont see any compile time issue with your code, but you may wana do a simplistic query first.
First of all, the statement and conection close, do it in the finally block, untill unless you are reusing it.
other than this.
First, after connection, see if you are getting the connection or not.
conn = dataSource.getConnection();
//print the connection and check if the connection is fine.
comment remaining stuff in the loop.
In the second shot, run a simple query like select count(*) from TABLE ;
to see if the connection and execution is fine. this will make sure
Also, before you set the values into the statement using setString, print the values to check for correctness and not null.
btw, i found an extra ")" in your setString(12,.....) ;
stmt.setString(12, wdContext.currentContextElement().getHuIndicator));
What are you trying to close in your finally block when you have already closed the connection in the try.
try{
---
---
---
stmt.close();
conn.close();
} catch (SQLException ex) {
msgMgr.reportException(
ex.getLocalizedMessage() + ";SQL State - " + ex.getSQLState(),
true);
} catch (Exception ex) {
msgMgr.reportException(ex.getLocalizedMessage(), true);
finally {
try {
conn.close();
} catch (Exception e) {
msgMgr.reportException(e.getLocalizedMessage(), true);
}
}
Remove it from try.
Regards,
Nitin
Edited by: Nitin Mahajan on Jun 16, 2009 6:20 PM
Edited by: Nitin Mahajan on Jun 16, 2009 6:21 PM
Edited by: Nitin Mahajan on Jun 16, 2009 6:22 PM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
As you have already set the conn = null / conn.close, in finally, it will always throw a null pointer exception, without fail, so this is surely one area of failure.
To verify your code is working fine. you need to comment the executeupdate command line and see if the code works.
This way, you will be sure where the error is. Right now because you are not getting any response, we do not know where the error is. So as i suggested earlier, try to find out by commenting the execute statement.
Also, you should close the connection and statement objects only in Finally. you can take out the conn.close and other close statements to finally.
should go like this.
finally{
try{
conn.close();
statement.close() ;
conn = null ;
statement = null ;
}catch(exception e){
//println( "exception while closeing the conn/statement" ) ; }
}
Regards,
Nitin
Edited by: Nitin Mahajan on Jun 16, 2009 11:27 PM
I was trying to write stored procedure on oracle to tackle this problem but ..I am getting this error when I try to execute the stored procedure in my controller
java.lang.UnsupportedOperationException: Method prepareCall is not supported by Open JDBC
is it is possible to execute stored procedure in Java Webdynpro ?
This code I was trying to execute -
CallableStatement cstmt = conn.prepareCall("{call zdeleterows[(?,?)]}") ;
cstmt.setString(1,wdContext.currentTableElement().getAUFNR());
cstmt.setString(2,wdContext.currentTableElement().getHUCASE());
cstmt.execute();
cstmt.close();
Thanks,
Manish
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This is my code -
+ Connection conn = null;+
+ try {+
+ wdContext.currentContextElement().getMsg().reportSuccess(+
+ wdContext.currentTableElement().getAUFNR());+
+ InitialContext ctx = new InitialContext();+
+ DataSource dataSource =+
+ (DataSource) ctx.lookup(readPropertyFiles());+
+ conn = dataSource.getConnection();+
+ PreparedStatement stmt =+
+ conn.prepareStatement(+
+ "delete from zae_prod_vrtrans where aufnr = ? and hucase = ?");+
+ stmt.setString(1, wdContext.currentTableElement().getAUFNR());+
+ stmt.setString(2, wdContext.currentTableElement().getHUCASE());+
+ stmt.execute();+
+ stmt.close();+
+ PreparedStatement stmtGR =+
+ conn.prepareStatement(+
+ "delete from zae_prod_grtable where aufnr = ? and exidv_c = ?");+
+ stmtGR.setString(1, wdContext.currentTableElement().getAUFNR());+
+ stmtGR.setString(2, wdContext.currentTableElement().getHUCASE());+
+ stmtGR.execute();+
+ stmtGR.close();+
+ conn.close();+
+ wdContext.nodeTable().invalidate();+
+ PopulateTable();+
+ } catch (SQLException ex) {+
+ wdContext.currentContextElement().getMsg().reportException(+
+ ex.getLocalizedMessage(),+
+ false);+
+ } catch (NamingException ex) {+
+ wdContext.currentContextElement().getMsg().reportException(+
+ ex.getLocalizedMessage(),+
+ false);+
+ }+
Hi,
First check that your query is executing properly in SQL studio (Database client). If it is working properly then we can think about WebDynpro. Sometimes there is a possibility of data issue which causes deadlock. So your WebDynpro application hangsup.
So try executing the query first in SQL studio (Using Database client).
Regards,
Charan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Just check whether you have nested for loops (for loop inside another for loop) in the code. This causes performance issue.
And try to debug your code where you are doubtful as below.
long before=System.currentTimeMillis();
...........code.................................
long after=System.currentTimeMillis();
long total=after-before;
Regards,
Charan
User | Count |
---|---|
101 | |
13 | |
13 | |
11 | |
11 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.