Oracle Cached Prepared Statement
We recently upgraded from WL 8.1 SP3 to WL 9.2 and in the process updated the JDBC Driver for Oracle from 10.2.0.1 to 10.2.0.2. After we went live we started seeing issue in one table. The table contains some special character which is not suppose to be there.
Here is the code & table details
PreparedStatement pstmt = cn.prepareStatement("INSERT INTO INFO_TABLE(user_name,user_status) values (?,?)");
pstmt.setString(1,requestObject.getUserName());
if(requestObject.isValidUser)
pstmt.setInt(2,requestObject.getStatus());
}else
pstmt.setNull(2,Types.VARCHAR);
cn.commit();
Table description:
USER_NAME VARCHAR2(60);
USER_STATUS VARCHAR2(5);
- The USER_STATUS columns valid values are 0-4 or NULL.
The problem is on certain occasions the valid user value in the table is some special character. I got the ascii value of this character as 128. We don't know yet whether setting int value and varchar (null) value on two different flow (but cached prepared statement) is the issue.
We can fix the code to use uniform data type but we need to be sure this is what causing the problem. Further when I read the docs http://e-docs.bea.com/wls/docs90/jdbc_admin/jdbc_datasources.html
I can associate the problem I face with this pointer however as I said, we need some sort of confirmation to make this change in the production code.
Here is what I am specifically looking for
1. Is there a way to confirm this problem?
2. Can we log the prepared statement being executed and the binded value being sent to the Oracle DB?
I suspect the VARCHAR null type is being casted to int value 128.
Would really appreciate any pointers on this.
Thanks
Purushothaman Thambu wrote:
We recently upgraded from WL 8.1 SP3 to WL 9.2 and in the process updated the JDBC Driver for Oracle from 10.2.0.1 to 10.2.0.2. After we went live we started seeing issue in one table. The table contains some special character which is not suppose to be there.
Here is the code & table details
PreparedStatement pstmt = cn.prepareStatement("INSERT INTO INFO_TABLE(user_name,user_status) values (?,?)");
pstmt.setString(1,requestObject.getUserName());
if(requestObject.isValidUser)
pstmt.setInt(2,requestObject.getStatus());
}else
pstmt.setNull(2,Types.VARCHAR);
cn.commit();
Table description:
USER_NAME VARCHAR2(60);
USER_STATUS VARCHAR2(5);
- The USER_STATUS columns valid values are 0-4 or NULL.
The problem is on certain occasions the valid user value in the table is some special character. I got the ascii value of this character as 128. We don't know yet whether setting int value and varchar (null) value on two different flow (but cached prepared statement) is the issue.
We can fix the code to use uniform data type but we need to be sure this is what causing the problem. Further when I read the docs http://e-docs.bea.com/wls/docs90/jdbc_admin/jdbc_datasources.html
I can associate the problem I face with this pointer however as I said, we need some sort of confirmation to make this change in the production code.
Here is what I am specifically looking for
1. Is there a way to confirm this problem?
2. Can we log the prepared statement being executed and the binded value being sent to the Oracle DB?
I suspect the VARCHAR null type is being casted to int value 128.
Would really appreciate any pointers on this.
ThanksHi. I don't think there's any issue with WebLogic here, but the code you show
might confuse some drivers. I highly recommend using setString for all
varchar/char/varchar2 columns, not setInt(). If requestObject.getStatus()
has to return an int, try this:
if(requestObject.isValidUser)
pstmt.setString(2, (""+ requestObject.getStatus()) );
Joe
Similar Messages
-
Prepared Statement Cache in WLAS 6.0 sp2
Does 6.0 sp2 cache prepared statements like 6.1.
I have heard yes and no and if so is there a way to disable it like in
6.1Larry Presswood wrote:
>
Ok so is there a way to disable it in 6.0 sp2 that you know of??To disable it, add this jar file to the front of the server's classpath.
Joe
>
Cameron Purdy wrote:
It's been there since 5.1 (sp6 or sp9?)
Peace,
Cameron Purdy
Tangosol, Inc.
Clustering Weblogic? You're either using Coherence, or you should be!
Download a Tangosol Coherence eval today at http://www.tangosol.com/
"Larry Presswood" <[email protected]> wrote in message
news:[email protected]..
Does 6.0 sp2 cache prepared statements like 6.1.
I have heard yes and no and if so is there a way to disable it like in
6.1
[60nocache.jar] -
Use of Prepared Statement in adf
Hi Experts,
I am confused with the Use of prepared statement in adf.
My use case is ,
I have to update a table from every page in my application under certain conditions.
My question is ,
whether I have to create the VO iterator binding in every page and by calling the createinsert and insert the data in to the table or
use a common method in the Application module impl
which is using a prepared statement,(which is not even creating the ViewObject ) like
PreparedStatement st = null;
String sql = "INSERT INTO hr.departments (DEPARTMENT_ID, DEPARTMENT_NAME, MANAGER_ID, LOCATION_ID) VALUES (seq,?,?,?)";
st=getDBTransaction().createPreparedStatement(sql,0);
st.setString(1, name);
st.setString(2, mgr_id);
st.setString(3, Loc_id);
st.execute();
getDBTransaction().commit();which is the best approach?
Studio Edition Version 11.1.1.2.0
RanjithRanjith,
Without further understanding the use case, there's not really much difference between the two approaches. In both cases, you'd have a binding in the page definition (either an iterator binding for the VO or a method binding for the AM service method). Both will use bind variables. The main difference I can see is that, depending on how you have configured your AM pooling settings, the VO method will incur fewer parses in the DB because the AM will cache prepared statements for you.
John -
When to use prepared statement in java?
Hi all,
If we have query like select * from {tablename} (Here tablename is the variable) then will the use of prepared staement improve the performance? My guess is use of statement in this case is a better option rather than prepared statement as the tablename may change for every other query.I think are not useful if tablename changes.They are useful only when the where clause has dynamic values.cantor wrote:
Are you sure that your approach is possible? The next example causes exception for me.
PreparedStatement ps = conn.prepareStatement("select * from ?");
ps.setString(1, "TABLE_NAME");
ps.executeQuery();
I didn't say that he should solve it in that way. He should create one prepared statement like this "select a, b, c from tablename1" and another prepared statement when he wants to execute "select d, e, f from tablename2"
>
And as I understand, this code will not improve perfomance (and even will not work). As I said it can.
Prepared statements make possible usage compiled queries inside DB. When DB gets prepared statement call, it need to parse it only once. And it can collect some statistic to improve execution plan. But when table name is not specified, this approach will not work.Yes it might. There are database drivers that can cache prepared statements and it's isn't likely that he executes that query on more than e.g. 20 tables?
The database can also cache compiled statements in a cache.
Kaj -
Pooling Prepared Statement and Resultset
Is their any mechanism in Weblogic by which we can pool prepared statements and
resultset.Yes you can cache prepared statements. The connection pool will
automatically cache the prepared statements (10 prepared statement was the
limit in previous so you may want to write some startup class to load the
imp prepared statements.). When you reuse the prepared statement the
connection pool will pick it from its prepared statement cache. In 6.1 you
can configure the number of prepared statements that you want to cache.
But you cannot have multiple resultsets open for the same statement object.
You can have cache rows though.
Please search the bea newsgroups for more info. There are a bunch of posts
that will be helpful to you.
http://search.bea.com/weblogic/gonews/
sree
"hogan" <[email protected]> wrote in message
news:3bd9cf88$[email protected]..
>
Is their any mechanism in Weblogic by which we can pool preparedstatements and
resultset. -
Keep prepared statement across commit
Hello everyone!
Is there any way the Oracle keeps prepared statements across commits (same connection, same process)?
Thank you in advance
WolfgangCaching this occurs transparently, even across sessions. No need to do anything special...
-
Prepared statement cache & Oracle
Hi -
Does Weblogic's prepared statement caching only work when using their
type-2 Oracle driver? Are there any documents about using this
Weblogic feature? I have only found small references in the Weblogic
documentation so far -- nothing with much detail.
Thanks for any help,
- Mark"Joseph Weinstein" <[email protected]> wrote in message
news:[email protected]..
>
>
Mark Cassidy wrote:
Hi -
Does Weblogic's prepared statement caching only work when using their
type-2 Oracle driver?No. It is generic to JDBC. Any JDBC driver should allow re-use ofPreparedStatements,
and our pool will cache for any driver.
Are there any documents about using this
Weblogic feature? I have only found small references in the Weblogic
documentation so far -- nothing with much detail.You are correct that there is too little documentation at this time.
Thanks for any help,
- Mark
Thanks Joe!
Do you know if each connection's cache is FIFO? Or do you use
least-recently-used algorithm?
I found one comment you made regarding XA pools. That means that if we are
doing 2-phase commit processing that some of these benefits could erode? I
didn't understand why. If we assume that the connections in a given pool
after a time get a good sampling of popular prepared statements, would their
being XA or not matter? Maybe I missed your point entirely.
- Mark -
Jboss getting SQLException: Closed Statement prepared-statement- cache-size
My first post in this forum , hope to get a quick resolution :)
I am using Jboss 4.0.0 on Oracle 9.2.0.4.0
In order to improve the app performance , I had specified prepared-statement-cache-size as 50 as follows ,
<datasources>
<local-tx-datasource>
<jndi-name>jdbc/sct</jndi-name> <connection-url>jdbc:oracle:thin:@confidential:1560:sct1</connection-url>
<user-name>Confidential</user-name>
<password>Confidential</password>
<min-pool-size>10</min-pool-size>
<max-pool-size>120</max-pool-size> <prepared-statement-cache-size>50</prepared-statement-cache-size>
<exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptio nSorter</exception-sorter-class-name>
<idle-timeout-minutes>5</idle-timeout-minutes>
<track-statements>true</track-statements>
<new-connection-sql>select sysdate from dual</new-connection-sql>
<check-valid-connection-sql>select sysdate from dual</check-valid-connection-sql>
</local-tx-datasource>
</datasources>
After doing this , I start getting the following exception ,
java.sql.SQLException: Closed Statement
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:180)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:222)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:285)
at oracle.jdbc.driver.OracleStatement.ensureOpen(OracleStatement.java:5681)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.j ava:409)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.ja va:366)
at org.jboss.resource.adapter.jdbc.CachedPreparedStatement.executeQuery(CachedPrepare dStatement.java:57)
at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.executeQuery(WrappedPrepa redStatement.java:296)
at com.ge.sct.SiteText.getSiteTextFromDB(SiteText.java:292)
Thanks in Advance
BhavinHello,
I am also facing the same error: somewhere just now I read,
We were getting this error on JBoss / Oracle. The fix was setting the following to 0 in oracle-ds.xml:
<prepared-statement-cache-size>0</prepared-statement-cache-size>
Ref: http://www.jpox.org/servlet/forum/viewthread?thread=1108
May be you can try this, I am also still finding the solution, I will try the above and let u know, if i get success.
Regards,
Rajesh -
Startup class for prepared statement cache
Hi
we are using weblogic 7.0 sp1 . As clearcacheparamters method is not available
with this version ,we have written a startup class to cache the preparedstaments
that we need ,even then these statements are not getting cached .we have observed
the oracle trace,it is parsing the prepared statement each time we make a call.Can
anyone clarify where iam doing wrong and suggest me a way to cache the prepared
statements we wanted.
my sample startup class looks like this
Collection connections = new ArrayList();
int conCount = 0;
Connection con =null;
PreparedStatement prep1=null;
PreparedStatement prep2=null;
PreparedStatement prep3=null;
while(true)
try
con = SQLConnection.getConnection();
connections.add(con);
prep1 = con.prepareStatement(sql1);
prep2 = con.prepareStatement(sql2);
prep 3 = con.prepareStatement(sql3);
conCount++;
catch (SQLException e)
System.out.println("exception SQLException "+e.getMessage());
break;
catch (IOException e)
System.out.println("******StartUp Connections got ---> "+conCount);
try
Iterator connectionIt = connections.iterator();
while(connectionIt.hasNext())
con = (Connection) connectionIt.next();
con.close();
catch (SQLException e)
we cant upgrade to sp3 immediately ,so please provide a solution for weblogic
7.0 sp1.
Thanks & Regards
RangaHi
we are using weblogic 7.0 sp1 . As clearcacheparamters method is not available
with this version ,we have written a startup class to cache the preparedstaments
that we need ,even then these statements are not getting cached .we have observed
the oracle trace,it is parsing the prepared statement each time we make a call.Can
anyone clarify where iam doing wrong and suggest me a way to cache the prepared
statements we wanted.
my sample startup class looks like this
Collection connections = new ArrayList();
int conCount = 0;
Connection con =null;
PreparedStatement prep1=null;
PreparedStatement prep2=null;
PreparedStatement prep3=null;
while(true)
try
con = SQLConnection.getConnection();
connections.add(con);
prep1 = con.prepareStatement(sql1);
prep2 = con.prepareStatement(sql2);
prep 3 = con.prepareStatement(sql3);
conCount++;
catch (SQLException e)
System.out.println("exception SQLException "+e.getMessage());
break;
catch (IOException e)
System.out.println("******StartUp Connections got ---> "+conCount);
try
Iterator connectionIt = connections.iterator();
while(connectionIt.hasNext())
con = (Connection) connectionIt.next();
con.close();
catch (SQLException e)
we cant upgrade to sp3 immediately ,so please provide a solution for weblogic
7.0 sp1.
Thanks & Regards
Ranga -
Oracle Prepared Statement and spaces in field
I have a field that is defined as char(10). It has characters like '39' in it. When I select against it using standard SQL (where clause) I get results. When I use it in the where clause of a prepared statement it does not return any rows.
If I have the field defined as char(2) the prepared statement works.
If I have the field defined as varchar2(10) and loaded with '39' the prepared statement works.
If I have the field defined as varchar2(10) and loaded with '39 ' the prepared statement returns no results.
I really do not think this is a JDBC problem. However, since Oracle's site basically <expletive deleted>, I am hoping someone here has a solution.
Thanks in advance if you can help.Let me clarify.
I cannot remove the whitespace from the data in the database. I do not need the whitespace to do the query if I am not using a Prepared Statement. This seems to be a problem with the way Oracle is handling the prepared statement. (hence.. my thinking that this is really not a JDBC problem at all.. but I could be wrong.) -
Using once created prepared statement with different connections in Oracle
Can I use same statement cash using different connections in Oracle
For example I have a prepared statement p1. After its using i close connection (return it to the pool)
Next time I want use p1 statement using another connection.
Question : When I creat p1 in second time ,is it returned from cash or created as a new statement. And what I should do to use once prepared statement using differend connections.
Thaks.As far as I know a PreparedStatement lives and dies with the Connection that created it. So, you cannot use a PreparedStatement with other Connection instances than the one that created it.
You will have to recreate the PreparedStatement for each time you open a connection, or use the same PreparedStatement and NOT close the Connection in between. The last suggestion can be risky though, if you never close the connection...
Jakob Jenkov
www.jenkov.com -
Oracle Prepared Statement - 8.1.7 JDBC type II Driver
Hi,
I have a strange problem.
I do a query using a prepared statement and there are no matching results.
I change this to hardcoded SQL Statement and pass in the same value a row of record is returned
I change this to Statement and pass in the input a row of record is returned.
This is puzzling. There seems to be a problem with Prepared Statement and I can't see why that fails.
The Stmt looks like this
PreparedStatement id is defiend as a char in the database
Code Snippet:
SQL = Select * from employee where id = ?;
pstmt.setString(1,'value');
Hardcoded SQL:
select * from employee where id = 'value';
Statement Impl:
String var = "value";
"select * from employee where id = '" + var+ "'";
Would appreciate if somebody can explain what's happening. To me it is bizarre!
Thanks,
MangluUpdate to problem
I have the latest (classes12.zip) JDBC drivers from Oracle.
We are running Oracle 8.1.6 and converting to Oracle 8.1.7.
This works the same with both.
Example, I have a column (char(10)) with trailing spaces. i.e. '39 '.
When I perform a Prepared Statement with that column in the where clause, it returns no result rows.
When I perform a standard statement with that column in the where clause, it returns rows.
When I define a column char(2) and use it in the where clause it works fine.
When I define a column varchar2(10) and load it with data like '39', it works fine.
When I define a column varchar2(10 and load it with data like '39 ', it does not work.
When I execute this same Prepared Statement through the jdbc:odbc bridge it works fine.
I cannot change the definition of the columns as they are foreign key data. What is the problem here? Any help is appreciated.
If you need further information please feel free to contact me. -
Oracle Called vs. Prepared Statement - Know the difference?
If anyone can explain why i would use one rather than the other I would appreciate it.
Thanks,
CHrisChris,
A Prepared Statement is parsed and compiled SQL statement. It is intended to be executed a number of times and can contain placeholders (See the answer to you question above).
A Callable Statement allows Oracle stored procedures, packages and functions to be executed from inside Java.
hth
Simon
null -
How to retrieve a prepared statement from prepared statement cache?
Hi All,
I have created the connection pool during application server startup. The connection pool are getting created successfully. I have also created the prepared statements and stored as part of each connection in the connection pool.
can anyone please tell me on how do I retrieve a prepared statement from prepared statement cache from a connection object.
Any pointers to info source will be REALLY appreciated.
Many Thanks in Advance,
C R BaradwajRaghuram Bharatwaj C wrote:
Hi Joe,
I have created a connection poool in my startup class and created the
neccessary prepared statements for a each connection. I have 10 prepared
statements to be created for each connection. I have created all the 10 prepared statements using the loop as mentioned below
String [] epc_stmts;
private java.sql.PreparedStatement[] _pstmts;
if (epc_stmts!= null)
_pstmts = new PreparedStatement [len = epc_stmts.length];
for (i=0; i<len; i++)
_pstmts[i] = db.prepareStatement (epcstmts);
I have closed the connection after the prepared statements are created.
Now, How do i access a prepared statement from the connection object.
Nothing. Are you talking about a WebLogic pool? If so, then therafter,
whenever your application gets a pool connection, when it calls
prepareStatement() with the same SQL as you prepared those statements,
it will get a cached statement. Your array is unnecessary.
Joe
>
Many Thanks in Advance,
C R Baradwaj -
Prepared Statement nested calls (Oracle)
I have a prepared statement like
select type
, id
from ms_page_position where page_id =
(select id from ms_url where url = ?)
and column_id =
(select id from ms_column where name = ?)
and preview = ? order by position asc.
If i place in
pstmt.setString(1, "/news/");
pstmt.setString(2, "RIGHTCOLUMN");
pstmt.setString(3, "Y");
res = pstmt.executeQuery();The three fields are strings
i get this error -
java.sql.SQLException: ORA-01460: unimplemented or unreasonable conversion requested.
If i use a straight statement object and concatenate strings then i have no problem. Can you use prepared statements with nested selects - ?
CheersI've exactelly the same problem. Any ideas how to solve this. Concatenation works fine but two setString() on PS couses this exception.
Maybe you are looking for
-
File Adapter - anonymous login (or )User name ,password login - Efficient?
Hi Folks, In File Adapter processing , anonymous login (or) proper user name password based login is recommended ? Because we have faced many issue while using username based login in File adapter . Which one is best ? Regards., Shiva
-
Why won't my iCal icon display todays date ......
...... in the menu bar when the program is closed? It always displays Jul 17th Regards J
-
I've got Eureka plug-ins, and very good they were too before I upgraded to Snow Leopard! Any suggestions for getting them to work, as updates don't seem to be available? If not - suggestions for good plug-in libraries, especially for adding film scra
-
Restoring from DVD to new Drive.
Hey, I new my hard drive on my laptop was bailing so i backed up everything to DVD from my iTunes. Now it wont restore to the new drive. What do do.?
-
BAdi HRPAD00INFTY - Dynamically change the value of Wage amount in Infotype
Hello all, I am implementing BAdi HRPAD00INFTY for infotype 0008. The requirement is, whenever user checks/saves Infotype 8, System should look out FTE wage type exists or not. If it exists then amount should be calculated and get updates for that wa