Casting Decimals in Oracle
This code worked as a query in DB2, but I am not sure what the syntax is for casting decimals in Oracle:
decimal(decimal(A.record_count-A.generic_count-A.unusable_count,10,2) / decimal(B.record_count,10,2) * 100,10,2) usable_percent
The full query is:
SELECT B.load_date,
B.dsrc_id,
C.dsrc_code,
A.table_seq,
A.table_name,
A.record_type,
B.record_count total_records,
A.record_count,
A.generic_count,
A.unusable_count,
A.record_count-A.generic_count-A.unusable_count usable_count,
decimal(decimal(A.record_count-A.generic_count-A.unusable_count,10,2) / decimal(B.record_count,10,2) * 100,10,2) usable_percent
FROM (select load_id, table_seq, table_name, record_type,sum(record_count) record_count, sum(generic_count) generic_count, sum(unusable_count) unusable_count
from umf_sum_quality group by load_id, table_seq, table_name, record_type) A,
(select load_id, dsrc_id, load_date, sum(record_count) record_count
from umf_load_sum group by load_id, dsrc_id, load_date) B,
dsrc_code C
WHERE B.load_id = A.load_id and C.dsrc_id = B.dsrc_id
ORDER BY B.load_date desc, B.dsrc_id, A.table_seq, A.table_name, A.record_type
If you are running on isqlplus or sql *plus
set numformat 99999999999999999999.99999999999999but all numeric values follows the above format.
If the expression's output comes with huge decimals then you can use the Round Function
Round (Expression,N)
N- No of digits required in the decimal area.
Kanish
Similar Messages
-
CAST function in Oracle Forms9i Version 9.0.2.9.0
Hi,
When trying to compile a procedure with line
SELECT * FROM TABLE(CAST(pl_tbl_employee AS sc_typ_employee))
I get the following error
"Implmentation restirction(may be temporary)ADT or schema level collection not supported at the client side with non-OCI mode"
My forms builder Oracle Forms 9i Version 9.0.2.9.0
PL/SQL Version 9.0.1.3.1
DB is Oracle 8i
Thanks for ur valuable inputsThe HP-UX version of XDK will be available with the 9iR2 DB for HP-UX.
-
Hi ,
Now iam migrating my system from SQL to ORACLE 9i.
Here USERID is of NUMBER(38) type
and DATA is of LONG type in SQL.
I have table named :
PEOPLE and DBATABLE and i run the following code in oracle but found the following error...
ORA-00932: inconsistent datatypes:
SELECT P.USERID FROM PEOPLE P LEFT OUTER JOIN (SELECT DATA FROM DBATABLE WHERE NAME='USER' ) R ON CAST(DATA AS VARCHAR(50))= CAST(P.USERID AS VARCHAR(50)) WHERE P.USERLOGID= 1000 AND R.DATA IS NULL;
So help me for finding my error.
I have missed somewhere but could not find what i missed .
Plz help me out.
With regards,
NamusI messed up with the type conversion of :
USERID -> NUMBER(38)
and DATA -> LONG type in SQL.
I have the checked in the database and found the value of the Column DATA with 31 and when i try to run as :
SELECT DATA FROM DBATABLE WHERE NAME='USER' AND DATA = '31'.
it gives error : Illegal use of the Long datatype and then i tried to cast as :
SELECT CAST<DATA AS INTEGER> FROM DBATABLE WHERE NAME='USER' AND DATA = '31'.
it also give error as:
FROM keyword not found where expected
So plz help me out with this conversion. -
Parameter.Value proper cast with c# oracle number to c# int??
Hello,
I'm trying to get a return value from an Oracle stored function using C# and odp.net.
The function basically looks like:
function f( id in number ) return number
is
id_new number := null;
begin
select sequenct_name.nextval
into id_new
from dual;
-- do some stuff
return id_new;
end;
The C# call basically looks like
cmd.Parameters.Clear();
cmd.CommandText = "f";
cmd.CommandType = CommandType.StoredProcedure;
// set up return variable
ret = cmd.Parameters.Add( "id_new", // name
OracleDbType.Decimal ); // type
ret.Direction = ParameterDirection.ReturnValue;
// pass in original id
cmd.Parameters.Add( "id", // name
OracleDbType.Decimal, // type
id, // value
ParameterDirection.Input ); // direction
cmd.ExecuteNonQuery();
if ( ret.Value != null ){
// ai_id_new = (int) ret.Value;
// ai_id_new = (OracleDbType.Decimal ret.Value;
// ai_id_new = (int)(decimal) ret.Value;
// ai_id_new_d = (decimal) ret.Value;
// ai_id_new = (int)(Int32) ret.Value;
// ai_id_new = (Int32) ret.Value;
ai_id_new = int.Parse(ret.Value.ToString());
You can see all of the casts that I had to comment out. The last line works, but I don't like it:
ai_id_new = int.Parse(ret.Value.ToString());
Does anyone know what the proper cast is for the ret.Value Object?? to get it assigned back to a C# int?
Thanks,
Davidfigured it out
have to do this in c# file
int ai_new_id;
OracleDecimal ora_dec;
ora_dec = (OracleDecimal) ret.value;
ai_new_id = ora_dec.ToInt32(); -
Class cast exception about oracle db
I want to store image file into BLOB of oracle datebase.
first, i insert a empty BLOB, like "insert into tableName (blobField, ...) values(empty_blob(), ...)"
then, i will retrieve this record to update the BLOB field, like "select blobField from tableName ..."
when i want to cast java.sql.ResultSet to oracle.jdbc.driver.OracleResultSet,
like "BLOB = ((OracleResultSet)rs).getBLOB(1);"
exception throwed:
java.lang.ClassCastException: weblogic.jdbc.rmi.SerialResultSet
the connection is get from connection pool of weblogic.
otherwise, if i register a new single connection, it can work correctly.
of course the same jdbc driver is used.
who can tell me, where raise the problem?
Thanks!Don't cast to OracleResultSet but use the WebLogic API to set/get BLOBS:
http://edocs.bea.com/wls/docs61/oracle/advanced.html#1158561 -
Class Cast exception in oracle.sql.ArrayDescriptor
hi
i am trying to pass ArrayList to Oracle procedure
but when i am excuting the code i got the following error
java.lang.ClassCastException: com.ibm.ws.rsadapter.jdbc.WSJdbcConnection incompatible with oracle.jdbc.OracleConnection
Can anybody help me to resolve this problem.
Thanks
AnishWelcome to the forum!
>
am trying to pass ArrayList to Oracle procedure
but when i am excuting the code i got the following error
java.lang.ClassCastException: com.ibm.ws.rsadapter.jdbc.WSJdbcConnection incompatible with oracle.jdbc.OracleConnection
Can anybody help me to resolve this problem.
>
Not if you don't provide the code you are using so we can see what it is doing. Also post your 4 digit Oracle version, Java version, JDBC jar file name/version and the procedure signature that shows the language, parameters and types.
An ArrayList is a Java object so are you using a Java stored procedure?
Or are you using WebSphere? If WebSphere see this IBM link which appears to apply to the problem you are describing.
http://www-01.ibm.com/support/docview.wss?uid=swg21409335 -
Problem with java.sql.Clob and oracle.sql.CLOB
Hi,
I am using oracle9i and SAP web application server. I am getClob method and storing that in java.sql.Clob and using the getClass().getName() I am getting the class name as oracle.sql.CLOB. But when I am trying to cast this to oracle.sql.CLOB i am getting ClassCastException. The code is given below
java.sql.Clob lOracleClob = lResultSet.getClob(lColIndex + 1);
lPrintWriter = new PrintWriter(new BufferedWriter (((oracle.sql.CLOB) lOracleClob).getCharacterOutputStream()));
lResourceStatus = true;
can anybody please tell me the what is the problem with this and solution.
thanks,
Ashok.Hi Ashok
You can get a "ClassCastException" when the JVM doesn't have access to the specific class (in your case, "oracle.sql.CLOB").
Just check your classpath and see if you are referring to the correct jar files.
cheers
Sameer
PS: Please award points if you find the answer useful -
We have an interesting situation where have to support our application on
both Weblogic 6.1 SP2 using an Oracle Type 2 driver and iPlanet using an
Oracle Type 4 driver. In our application we are using blob's, and in order
for our blob's to work with the Type 4 driver we must do a two stage process
where we insert an Oracle EMPTY_BLOB and then select the newly inserted
blob, cast it to oracle.sql.BLOB and upload it using streams.
Unfortunately, when this code runs on WLS the datasource/connection pool
substitutes some wrapper classes (or something) behind the scenes and we get
class cast exceptions as the blob is of type
weblogic.jdbc.rmi.SerialOracleBlob.
Is there any way to configure WLS connection pools/datasources so that it
doesn't use any weblogic classes and only uses oracle classes? We currently
have our 3rd Party Oracle drivers as the first entry in our classpath. We
can't switch to Oracle Type 2 on iPlanet (too buggy), or this would all be
moot and we'd simply use the more generic non-vendor specific way of
uploading blob's. And we can't cast to weblogic classes, because then that
would break on iPlanet.
Here's the code snippet that we can't change, because we have to support
Oracle Type 4 on iPlanet.
ResultSet blobs = ustmt.executeQuery();
blobs.next();
Blob blob = blobs.getBlob(1);
OutputStream blobOut = ((oracle.sql.BLOB)
blob).getBinaryOutputStream();
try {
blobOut.write(attachment.getFile());
} catch (IOException e) {
throw new ServletException(e);
} finally {
try {
blobOut.close();
} catch (IOException e) {
throw new ServletException(e);
blobs.close();
Thanks,
GaryHi Gary!
Blob oracle extensions are implemented internally in weblogic as
weblogic.jdbc.rmi.SerialOracleBlob. As we wrap objects internally for
serialization purpose, we can not use oracle objects directly. So, you have to
use SerialBlob in weblogic.
Mitesh
Gary Rudolph wrote:
We have an interesting situation where have to support our application on
both Weblogic 6.1 SP2 using an Oracle Type 2 driver and iPlanet using an
Oracle Type 4 driver. In our application we are using blob's, and in order
for our blob's to work with the Type 4 driver we must do a two stage process
where we insert an Oracle EMPTY_BLOB and then select the newly inserted
blob, cast it to oracle.sql.BLOB and upload it using streams.
Unfortunately, when this code runs on WLS the datasource/connection pool
substitutes some wrapper classes (or something) behind the scenes and we get
class cast exceptions as the blob is of type
weblogic.jdbc.rmi.SerialOracleBlob.
Is there any way to configure WLS connection pools/datasources so that it
doesn't use any weblogic classes and only uses oracle classes? We currently
have our 3rd Party Oracle drivers as the first entry in our classpath. We
can't switch to Oracle Type 2 on iPlanet (too buggy), or this would all be
moot and we'd simply use the more generic non-vendor specific way of
uploading blob's. And we can't cast to weblogic classes, because then that
would break on iPlanet.
Here's the code snippet that we can't change, because we have to support
Oracle Type 4 on iPlanet.
ResultSet blobs = ustmt.executeQuery();
blobs.next();
Blob blob = blobs.getBlob(1);
OutputStream blobOut = ((oracle.sql.BLOB)
blob).getBinaryOutputStream();
try {
blobOut.write(attachment.getFile());
} catch (IOException e) {
throw new ServletException(e);
} finally {
try {
blobOut.close();
} catch (IOException e) {
throw new ServletException(e);
blobs.close();
Thanks,
Gary -
Creating/constructing a java.sql.Blob and writing to Oracle with jdbc
I'm trying to understand how to create a blob from an image file to write it to a Oracle database using jdbc.
I know there'a a getBinaryStream method in java.sql.Blob to which I can write the files byte array, but how do I create an actual blob in the first place. All examples I've seen initialise the blob from an exiting Blob field in a database which I do not have filled yet
thanksIn general, you will do something like the following:
Ensure setAutoCommit is false
INSERT INTO foo (blob_column) values (empty_blob());
SELECT blob_column FROM foo FOR UPDATE;
Call getBlob() on the ResultSet
Cast it to Oracle's specific BLOB (different object)
Call getBinaryOutputStream() on the BLOB
Pipe your data
Commit (very importatnt as FOR UPDATE will lock that row)- Saish -
Unable to cast object of type OracleXmlType to type XmlDocument
Hello All:
I have an Oracle Procedure that is taking an XML Document as an output parameter.
oCommand.Parameters.Add("errorrecord", OracleDbType.XmlType).Value = System.DBNull.Value;
oCommand.Parameters["errorrecord"].Direction = System.Data.ParameterDirection.Output;
When I try to cast this as an XmlDocument so I can set it to my ErrorRecord variable (defined as XmlDocument) and pass it back out of the Web-Service
ErrorRecord = (XmlDocument)oCommand.Parameters["p_errorrecord"].Value;
I get the following error: "Unable to cast object of type 'Oracle.DataAccess.Types.OracleXmlType' to type 'System.Xml.XmlDocument'"
How do I cast / convert the Oracle XMLType back to a .Net XMLDocument to pass out of the function?
ThanksNo, I have not tried that yet, but I admit I don't fully understand the syntax in the document posted.
oCommand.Parameters.Add("p_errorrecord", OracleDbType.XmlType).Value = System.DBNull.Value;
ErrorRecord = GoCommand.Parameters["errorrecord"].Value; (this is returned as XmlType)
I don't quite understand the syntax in the posted URL:
Declaration
// C#
public XmlDocument GetXmlDocument();
How am I to use this to get the XMLDocument? -
Validate Oracle Apps Username and Password via ADF?
Hello. I'm trying to verify a persons user id and password in ADF 11g. I snagged the FND classes to be able to do this, and am calling it as follows:
AppsContext ac = new AppsContext("/home/workspace/idev.dbc");
boolean loginStatusCode = ac.getSessionManager().validateLogin(userName, password);
if(loginStatusCode == true)
return "success";
else
return "failure";
This works in the Application Module tester, and works as a standalone program. However, when I run it in weblogic I get a class cast exception (this can be fixed by removing the ojdbc5 & 6 files in the lib folder and replacing them with the ojdbc14 jar) Unfortunately, it fixes that problem but then all the ADF stuff breaks.
Has anyone used Oracles apps security for logging in a user? Or, is there a way to have Weblogic use the ojdbc14.jar for a singular deployment? Here's the class cast I get:
oracle.jbo.JboException: JBO-29000: Unexpected exception caught: java.lang.IllegalAccessError, msg=tried to access class oracle.jdbc.driver.OraclePreparedStatement from class oracle.apps.fnd.common.ProfileCache
Thanks in advance.Hi,
you can also validate an FND login using the FND_WEB_SEC.validate_login package if it's easier.
Brenden -
Workaround for using Oracle JDBC extension with WLS pooling
Reading the newsgroup I saw that many of us encountered the problems
with ClassCastException when tried to use Oracle JDBC extension
with WLS pooling. I also had.
In this case BEA recommends to use dangerous
method getVendorConnection() which exposes
the physical connection object to your code.
Yes it's really dangerous because of unsafe usage may breaks
WLS pooled connection(s).
Moreover, this practice will make your JDBC code
unportable (your JDBC code in addition to Oracle dependence
became Weblogic dependent):
void doSmth() {
Connection con = ...;
Connection vCon = ((WLConnection)con).getVendorConnection();
// + mess of usage con in one places and vCon in others
// (where Oracle extensions are needed)
// !Don't forget to don't close vCon!
Sux.
I found the workaround.
Introduction
============
Yes the real cause of ClassCastException is that
in depth of Oracle driver the casting
to class oracle.jdbc.driver.OracleConnection
(not to interface oracle.jdbc.OracleConnection)
is performed.
Someone can say that this is bug or pure desing.
Weblogic pooled connection provide dynamic
implementation for all public interfaces
which real physical (wrapped) connection object implements.
Great feature!
But I guess that all interface methods implemented
by simple call-delegation to physical (wrapped) connection object.
In case of oracle.jdbc.OracleConnection interface
this approach doesn't work for at least one its method:
public OracleConnection unwrap()
WLS pooled connection shoudn't implement this method by
delegation to physical connection object BUT should
return physical connection object itself!
// Wrong implementation of unwrap()
// delegation is used
public OracleConnection unwrap() {
return physicalConnection.unwrap();
// Right implementation of unwrap()
// physical connection returned
public OracleConnection unwrap() {
return physicalConnection;
Workaround
==========
1. Develop your own OracleConnection wrapper class:
import oracle.jdbc.OracleConnection;
import weblogic.jdbc.extensions.WLConnection;
public class MyOracleConnectionImpl implements OracleConnection {
private OracleConnection con;
public MyOracleConnectionImpl(OracleConnection connection)
throws SQLException
this.con = connection;
public OracleConnection unwrap() {
return (OracleConnection)
((WLConnection)con).getVendorConnection();
/* Implement all other methods by delegation to con object */
2. Don't get Connections directly from DataSource --
develop your own simple (may be static) utility
class which retrives Connections from dataSource
and returns them wrapped into your MyOracleConnectionImpl
to your code from some method:
puclic abstract class MyConnectionSource {
public static Connection getConnection() {
Connection con = // get it from DataSource
return new MyOracleConnectionImpl((OracleConnection)con);
3. Add attribute RemoveInfectedConnectionsEnabled="false"
to definition of your JDBCConnectionPool within config.xml
You may do it because of you `safely` use vendorConnection --
you don't expose it to application code.
4. Enjoy the Oracle JDBC extensions in your code!
Example:
Connection con = MyConnectionSource.getConnection;
ArrayDescriptor add =
ArrayDescriptor.createDescriptor("your_type", con);
Hope it helps to someone.
Best regards,
Eugene VoytitskyHello Eugene Voytitsky,
Thanks Eugene Voytitsky for your idea
I have tried the solution suggested by You, but it did not work.
It still throws ClassCastException.
I am sorry for posting the whole code of two classes below.
I did this to give you more clarity.
I am also indicating the place where the exception was thrown..
Please let me know if I am doing something wrong.
OracleConnection Wrapper class
package ejbTesting;
// sql imports
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.sql.Statement;
// util imports
import java.util.Map;
import java.util.Properties;
// imports from Oracle Driver Classes
import oracle.jdbc.OracleConnection;
import oracle.jdbc.OracleOCIFailover;
import oracle.jdbc.OracleSavepoint;
// import from Weblogic extensions
import weblogic.jdbc.extensions.WLConnection;
public class WeblogicConnectionWrapper implements OracleConnection
// oracle connection object
private OracleConnection connection;
public WeblogicConnectionWrapper (OracleConnection orclConnection)
try
this.connection = orclConnection;
catch(Exception unexpected )
unexpected.printStackTrace();
public OracleConnection unwrap()
try
// The datasource returns a weblogic.jdbc.pool.Connection
// This needs to be type casted to weblogic.jdbc.extensions.WLConnection
// Only this weblogic.jdbc.extensions.WLConnection CAN BE type casted
// to OracleConnection
return (OracleConnection) ((WLConnection) connection).getVendorConnection();
catch(Exception sqlException )
sqlException.printStackTrace ();
return null;
/* Implement all other methods by delegation to connection object */
public Connection _getPC()
return connection._getPC();
public void archive(int i, int j, String s)
throws SQLException
connection.archive(i, j, s);
public void assertComplete()
throws SQLException
connection.assertComplete();
public void clearWarnings()
throws SQLException
connection.clearWarnings();
public void close()
throws SQLException
connection.close();
public void commit()
throws SQLException
connection.commit();
public Statement createStatement()
throws SQLException
return connection.createStatement();
public Statement createStatement(int i, int j)
throws SQLException
return connection.createStatement(i, j);
public boolean getAutoClose()
throws SQLException
return connection.getAutoClose();
public boolean getAutoCommit()
throws SQLException
return connection.getAutoCommit();
public CallableStatement getCallWithKey(String s)
throws SQLException
return connection.getCallWithKey(s);
public String getCatalog()
throws SQLException
return connection.getCatalog();
public boolean getCreateStatementAsRefCursor()
return connection.getCreateStatementAsRefCursor();
public int getDefaultExecuteBatch()
return connection.getDefaultExecuteBatch();
public int getDefaultRowPrefetch()
return connection.getDefaultRowPrefetch();
public Object getDescriptor(String s)
return connection.getDescriptor(s);
public boolean getExplicitCachingEnabled()
throws SQLException
return connection.getExplicitCachingEnabled();
public boolean getImplicitCachingEnabled()
throws SQLException
return connection.getImplicitCachingEnabled();
public boolean getIncludeSynonyms()
return connection.getIncludeSynonyms();
public Object getJavaObject(String s)
throws SQLException
return connection.getJavaObject(s);
public DatabaseMetaData getMetaData()
throws SQLException
return connection.getMetaData();
public Properties getProperties()
return connection.getProperties();
public boolean getRemarksReporting()
return connection.getRemarksReporting();
public boolean getRestrictGetTables()
return connection.getRestrictGetTables();
public String getSQLType(Object obj)
throws SQLException
return connection.getSQLType(obj);
public String getSessionTimeZone()
return connection.getSessionTimeZone();
public int getStatementCacheSize()
throws SQLException
return connection.getStatementCacheSize();
public PreparedStatement getStatementWithKey(String s)
throws SQLException
return connection.getStatementWithKey(s);
public int getStmtCacheSize()
return connection.getStmtCacheSize();
public short getStructAttrCsId()
throws SQLException
return connection.getStructAttrCsId();
public boolean getSynchronousMode()
return connection.getSynchronousMode();
public int getTransactionIsolation()
throws SQLException
return connection.getTransactionIsolation();
public Map getTypeMap()
throws SQLException
return connection.getTypeMap();
public String getUserName()
throws SQLException
return connection.getUserName();
public boolean getUsingXAFlag()
return connection.getUsingXAFlag();
public SQLWarning getWarnings()
throws SQLException
return connection.getWarnings();
public boolean getXAErrorFlag()
return connection.getXAErrorFlag();
public boolean isClosed()
throws SQLException
return connection.isClosed();
public boolean isLogicalConnection()
return connection.isLogicalConnection();
public boolean isReadOnly()
throws SQLException
return connection.isReadOnly();
public String nativeSQL(String s)
throws SQLException
return connection.nativeSQL(s);
public Object openJoltConnection(String s, short word0, short word1)
return connection.openJoltConnection(s, word0, word1);
public void oracleReleaseSavepoint(OracleSavepoint oraclesavepoint)
throws SQLException
connection.oracleReleaseSavepoint(oraclesavepoint);
public void oracleRollback(OracleSavepoint oraclesavepoint)
throws SQLException
connection.oracleRollback(oraclesavepoint);
public OracleSavepoint oracleSetSavepoint()
throws SQLException
return connection.oracleSetSavepoint();
public OracleSavepoint oracleSetSavepoint(String s)
throws SQLException
return connection.oracleSetSavepoint(s);
public int pingDatabase(int i)
throws SQLException
return connection.pingDatabase(i);
public CallableStatement prepareCall(String s)
throws SQLException
return connection.prepareCall(s);
public CallableStatement prepareCall(String s, int i, int j)
throws SQLException
return connection.prepareCall(s, i, j);
public CallableStatement prepareCallWithKey(String s)
throws SQLException
return connection.prepareCallWithKey(s);
public PreparedStatement prepareStatement(String s)
throws SQLException
return connection.prepareStatement(s);
public PreparedStatement prepareStatement(String s, int i, int j)
throws SQLException
return connection.prepareStatement(s, i, j);
public PreparedStatement prepareStatementWithKey(String s)
throws SQLException
return connection.prepareStatementWithKey(s);
public void purgeExplicitCache()
throws SQLException
connection.purgeExplicitCache();
public void purgeImplicitCache()
throws SQLException
connection.purgeImplicitCache();
public void putDescriptor(String s, Object obj)
throws SQLException
connection.putDescriptor(s, obj);
public void registerApiDescription(String s, short word0, short word1, String
s1)
connection.registerApiDescription(s, word0, word1, s1);
public void registerSQLType(String s, Class class1)
throws SQLException
connection.registerSQLType(s, class1);
public void registerSQLType(String s, String s1)
throws SQLException
connection.registerSQLType(s, s1);
public void registerTAFCallback(OracleOCIFailover oracleocifailover, Object
obj)
throws SQLException
connection.registerTAFCallback(oracleocifailover, obj);
public void rollback()
throws SQLException
connection.rollback();
public void setAutoClose(boolean flag)
throws SQLException
connection.setAutoClose(flag);
public void setAutoCommit(boolean flag)
throws SQLException
connection.setAutoCommit(flag);
public void setCatalog(String s)
throws SQLException
connection.setCatalog(s);
public void setCreateStatementAsRefCursor(boolean flag)
connection.setCreateStatementAsRefCursor(flag);
public void setDefaultExecuteBatch(int i)
throws SQLException
connection.setDefaultExecuteBatch(i);
public void setDefaultRowPrefetch(int i)
throws SQLException
connection.setDefaultRowPrefetch(i);
public void setExplicitCachingEnabled(boolean flag)
throws SQLException
connection.setExplicitCachingEnabled(flag);
public void setImplicitCachingEnabled(boolean flag)
throws SQLException
connection.setImplicitCachingEnabled(flag);
public void setIncludeSynonyms(boolean flag)
connection.setIncludeSynonyms(flag);
public void setReadOnly(boolean flag)
throws SQLException
connection.setReadOnly(flag);
public void setRemarksReporting(boolean flag)
connection.setRemarksReporting(flag);
public void setRestrictGetTables(boolean flag)
connection.setRestrictGetTables(flag);
public void setSessionTimeZone(String s)
throws SQLException
connection.setSessionTimeZone(s);
public void setStatementCacheSize(int i)
throws SQLException
connection.setStatementCacheSize(i);
public void setStmtCacheSize(int i)
throws SQLException
connection.setStmtCacheSize(i);
public void setStmtCacheSize(int i, boolean flag)
throws SQLException
connection.setStmtCacheSize(i, flag);
public void setSynchronousMode(boolean flag)
connection.setSynchronousMode(flag);
public void setTransactionIsolation(int i)
throws SQLException
connection.setTransactionIsolation(i);
public void setTypeMap(Map map)
throws SQLException
connection.setTypeMap(map);
public void setUsingXAFlag(boolean flag)
connection.setUsingXAFlag(flag);
public void setWrapper(OracleConnection oracleconnection)
connection.setWrapper(oracleconnection);
public void setXAErrorFlag(boolean flag)
connection.setXAErrorFlag(flag);
public void shutdown(int i)
throws SQLException
connection.shutdown(i);
public void startup(String s, int i)
throws SQLException
connection.startup(s, i);
Util class to get Wrapped Connections from
datasource
package ejbTesting;
// j2ee imports
import javax.naming.InitialContext;
import javax.sql.DataSource;
// sql imports
import java.sql.Connection;
// imports from Oracle Driver Classes
import oracle.jdbc.OracleConnection;
* Wrapper class for the DataSource Connection from Weblogic pool
public class DataSourceConnectionWrapper
// datasource variable
private static transient DataSource datasource = null;
private static String dbName = "jdbc/workbench";
* Method that returns the database connection
public static Connection getConnection()
try
// initialsing the datasource object
initialiseDataSource ();
// Getting a connection from the datasource
Connection con = datasource.getConnection( );
// wrapping it custom wrapper class and
// returning the connection object
return new WeblogicConnectionWrapper((OracleConnection)con);
catch(Exception exception )
exception.printStackTrace();
return null;
private static void initialiseDataSource( ) throws Exception
if ( datasource == null )
try
InitialContext ic = new InitialContext( );
datasource = (DataSource) ic.lookup( dbName );
catch (Exception ne )
throw new Exception( "NamingException while looking up DataSource with
JNDI name" +
dbName + ": \n" + ne.getMessage( ) );
Exception Stack Trace
The line 46 in DataSourceConnectionWrapper
corresponds to
return new WeblogicConnectionWrapper((OracleConnection)con);
Which I feel is logical as the connection which we get from Weblogic
datasource cannot be type casted to OracleConnection
java.lang.ClassCastException: weblogic.jdbc.pool.Connection
at ejbTesting.DataSourceConnectionWrapper.getConnection(DataSourceConnectionWrapper.java:46) -
Class cast exception while casting FTPConnectionFactory object
Hi
I have SOA Suite Advanced installation - 10.1.3.4 MLR#5.
I have developed a BPEL which polls an FTP site using a JCA FTPConnectionFactory registered in JNDI - eis/Ftp/My_Ftp.
If file is present, then BPEL doesnt fetchs it... instead calls a java program through WSIF binding.
In java program i am retrieving the JNDI object - eis/Ftp/My_Ftp.. casting it to oracle.tip.adapter.ftp.FTPConnectionFactory and get the FTP host and credentials.
Now using those details i mannually create an FTP Connection and retieve the file.
This program worked for sure... but recently when i tried the same i got the ClassCastException while casting java.lang.Object got from JNDI to oracle.tip.adapter.ftp.FTPConnectionFactory. I havnt changed any thing on server since... could not understand why this issue has cropped now.
After lot of research the issue seems due to different Classloaders. JNDI object was loaded by ClassLoaderA and in my java program it is being loaded by ClassLoaderB.
And these two classloaders dont share classes with each other.
This is the code:
InitialContext ctx = new InitialContext();
Object jndiFTPObj = ctx.lookup("eis/Ftp/My_Ftp");
System.out.println("Got Object from JNDI is: "+jndiFTPObj+" ClassLoader - "+jndiFTPObj.getClass().getClassLoader());
// it prints -- Got Object from JNDI is: oracle.tip.adapter.ftp.FTPConnectionFactory@1aa3bbc ClassLoader - FtpAdapter:0.0.0
FTPConnectionFactory ftpConF = (oracle.tip.adapter.ftp.FTPConnectionFactory)jndiFTPObj;
// here i get error -- java.lang.ClassCastException: oracle.tip.adapter.ftp.FTPConnectionFactory
Thinking of RMI/IIOP i even tried:
FTPConnectionFactory ftpConF = (FTPConnectionFactory)PortableRemoteObject.narrow(ctx.lookup("eis/Ftp/My_Ftp"), FTPConnectionFactory.class);
it didnt solve the error.
I tried loading the class using the same loader as:
Class.forName("oracle.tip.adapter.ftp.FTPConnectionFactory",true,jndiFTPObj.getClass().getClassLoader());
even that didnt solve the error.
If any body has some idea... pls help
Thanks
InderIssue was due to ClassLoaders... tried to use the same classloader... but couldnt.
Eventually solved it by using Java Reflection.
Thx -
Obtaining an oracle.sql.STRUCT through a pooled JDBC connection
Hello,
I am using WebLogic Server 10 and and Oracle 10 and I am trying to obtain a vendor-specific oracle.sql.STRUCT from a ResultSet using a pooled connection defined in Weblogic. I need the vendor-specific object, rather than simply the java.sql.Struct implementation, because a third party library requires it.
What gets returned in the ResultSet is a non-exposed WebLogic wrapper object which implements java.sql.Struct, but which cannot be cast to an oracle.sql.STRUCT. I can use reflection on this object to find and call the getVendorObj() method to obtain the oracle.sql.STRUCT, but this solution is not acceptable because this is not a published API and is not guaranteed not to change in future versions.
How can I reliably obtain a vendor-specific implementation of java.sql.Struct through a WebLogic connection pool in WebLogic Server 10?
Thanks for any advice,
-Dan Schwemleindan schwemlein wrote:
Joe,
Thanks again. With your guidance, I have arrived at the following approach, which I'll post for the benefit of others, and which I'd be thankful if you would validate:
1) Import the jar com.bea.core.datasource-1.0.0.0.jar from %BEA_HOME%\modules, which is the only location of the class WLConnection, which is the only class with the getVendorConnection() method you refer to.
2) Get the logical connection from the pooled data source, cast it to a WLConnection, call getVendorConnection() to obtain an OracleConnection (from the ojdbc jar), and use this connection to obtain the required oracle.sql.STRUCT from an OracleResultSet.
3) Be aware of the limitations and follow the guidelines in the document http://e-docs.bea.com/wls/docs81/jdbc/thirdparty.html#1043646 regarding security, error handling, releasing resources (close only the logical connection), etc.
Does this sound like the approach you had in mind?
Thanks again,
-Danyes.
Joe
>
Re: Obtaining an oracle.sql.STRUCT through a pooled JDBC connection
Posted: Jul 16, 2007 3:21 PM
dan schwemlein wrote:
Thanks for the quick response!I was working today...
Thank you for the information about the connection being closed.
I will look into using this configuration setting.
You say that you can describe a way to get a handle on an unwrapped
pool object using some documented WLS-specific code. Are you referring
here to the getVendorConnection() method?yes.
This method does not help me
get the oracle.sql.STRUCT object, because even the connection returned
by getVendorConnection() returns a wrapped WL java.sql.Struct object
from a call to getObject().I don't believe it. If you are running in WLS, with a local pool,
the getVendorConnection() will give you the Oracle connection,
which will give you an Oracle statement, etc, down to an oracle
STRUCT object. Once you have a direct reference to the oracle connection,
we're not in the picture when it returns something to you.
It would be great if getVendorObj() were
documented and could be counted on in future versions. To use this
method, one would still have to access it via Java reflection, because
the wrapper class and its getVendorObj() method would be exposed in an
API, correct? Could this method be exposed in the API, so that reflection
doesn't need to be used, or it is exposed somewhere that isn't documented?getVendorObj() is not yet exposed or therefore supported for the general
wrapped object, so you would have to start from the connection and
derive all subobjects from it.
Thanks again,
-Dan Schwemlein
Hello,
I am using WebLogic Server 10 and and Oracle 10 and I am trying to obtain a
vendor-specific oracle.sql.STRUCT from a ResultSet using a pooled connection
defined in Weblogic. I need the vendor-specific object, rather than simply
the java.sql.Struct implementation, because a third party library requires it.
What gets returned in the ResultSet is a non-exposed WebLogic wrapper object
which implements java.sql.Struct, but which cannot be cast to an oracle.sql.STRUCT.
I can use reflection on this object to find and call the getVendorObj() method to
obtain the oracle.sql.STRUCT, but this solution is not acceptable because this is
not a published API and is not guaranteed not to change in future versions.Understood. We all benefit from sticking to the J2EE standards,
but we could also wish Oracle had done so with it's driver objects.
I will assume your code is running in the WebLogic server, because
an external JVM can never access the real driver object, which will
always really be in the WLS JVM. No active JDBC object is serializable.
How can I reliably obtain a vendor-specific implementation of java.sql.Struct
through a WebLogic connection pool in WebLogic Server 10?There is no way to get a handle on an unwrapped pool object without using some
WLS-specific code, though I can describe a way with documented methods,
and/or I can get our documentation altered to say we'll support the
getVendorObj() method. We introspect every vendor object, and for those
implementations that have done the wise thing, projecting any non-standard
methods as an Interface, we are able to also project that Interface so
the vndor example code should work. However, in some poorly-done
cases, such as for some Oracle stuff, there is either no Interface,
or the Oracle code has extensions that take java.sql objects as input,
(at least that's the signature of the method) but two lines into the
method, the Oracle code assumes and casts the java.sql object to a concrete
Oracle object. In these use cases you need the direct unwrapped object.
We provide and document Connection.getVendorConnection(), and intend
getVendorObj() to serve the same for subobjects, but note the dangers
and responsibilities: We rely on our wrappers to implement the security
and thread-safety of our pooling system. Because user code can get
unrestricted access to the actual connection from most JDBC objects,
we can never trust that we have complete control once a vendor object
is exposed. Therefore, by default we will close and replace every JDBC
connection so exposed, as soon as the current thread is finished with
the pool connection. This hurts performance. We also document a pool
config setting that will tell us that you take responsibility for any such
problems, and not to close connections just because they've been exposed.
HTH,
Joe
Thanks for any advice,
-Dan Schwemlein -
Wht does it mean - "ASSIGN it_DB_TBL_name TO fs1 CASTING TYPE x"?
Hi Experts,
Just curious,
Pls. let me know that, Wht is the functionality of the following statement:
ASSIGN it_DB_TBL_name TO <fs1> CASTING TYPE x
thanqASSIGN feld TO <fs> CASTING TYPE type.
ASSIGN feld TO <fs> CASTING TYPE (typename).
ASSIGN feld TO <fs> CASTING LIKE fld.
ASSIGN feld TO <fs> CASTING DECIMALS dec.
You can use ASSIGN ... CASTING to treat the contents of a field as a value of another type using a field symbol. One application for this statement would be to provide different views on a structure with casts on different types.
One wide-spread ABAP technique is to use C fields or structures as containers for storing structures of different types that are frequently only known at runtime. The components of the structure are selected with offset/length accesses to the container. Since this technique no longer works with Unicode, you can also look upon an existing memory area as a container with the suitable type definition using a field symbol with the ASSIGN ... CASTING statement. In the next example, a certain field of database table X031L is read, whereby the field and table names are only defined at runtime.
Example:
* Read a field of table X031L
PARAMETERS:
TAB_NAME LIKE SY-TNAME, "Table name
TAB_COMP LIKE X031L-FIELDNAME, "Field name
ANZAHL TYPE I DEFAULT 10. "Number of lines
DATA:
BEGIN OF BUFFER,
ALIGNMENT TYPE F, "Alignment
C(8000) TYPE C, "Table contents
END OF BUFFER.
FIELD-SYMBOLS:
<WA> TYPE ANY,
TYPE ANY.
* Set field symbol with suitable to buffer area
ASSIGN BUFFER TO <WA> CASTING TYPE (TAB_NAME).
SELECT * FROM (TAB_NAME) INTO <WA>.
CHECK SY-DBCNT < ANZAHL.
ASSIGN COMPONENT TAB_COMP OF STRUCTURE <WA> TO .
WRITE: / TAB_COMP, .
ENDSELECT.
Until now, in the ASSIGN feld TO <f> CASTING ... statement, the system checked to ensure that the field was at least as long as the type that was assigned to the field symbol, <f>. (Field symbols can either be typed at declaration or the type specified in an ASSIGN statement using CASTING TYPE). The syntax check is now more thorough. Now, you can only assign the field field (in either a Unicode or non-Unicode program)
provided it is at least as long as the type assigned to the field symbol <f>. Otherwise, the system returns a syntax error. At runtime, the system only checks to see whether or not the lengths are compatible in the current system (as before).
If the field type or field symbol type is a deep structure, the system also checks that the offset and type of all the reference components match in the area of field that is covered by <f>. The syntax check is now more thorough. Now, the system checks that these components must be compatible with all systems, whether they have a one-byte, double-byte, or four-byte character length. At runtime, the system only checks to see whether or not the reference components are compatible in the current system
In Unicode systems, in the ASSIGN str TO <f> TYPE C/N and ASSIGN str TO <f> CASTING TYPE C/N statements, the length of str may not always be a multiple of the character length, in which case the program terminates at runtime.
Maybe you are looking for
-
How can I change the encoding of a font "on the fly" in Illustrator
Is it possible to do that. I saw that in CorelDraw if you press Ctrl+Shift+E with a text selected a dialog windows appears with the option to choose beteen different code tables, so non unicode fonts can be made to show the right gliphs. Or maybe the
-
I have an iphone 5s and updated it to the new 7.1 software. A day later I go and use my phone and in the top left hand corner it says no service. i have tried restoring the pone, resetting the network settings and also a hard reset as well. It gains
-
Pavilion 17-f084nf. Need instructio​ns on how to replace the hard drive
I do not understand how to get to the innards Series 17-f000. I want to replace the HDD and RAM. There is a manual? This question was solved. View Solution.
-
How can download old photoshop like CS2 -3-4 for free MAC version?
-
when i open iPhoto and want to share my photo on face book its popup with problem occur and ask me to repair when i repair it appears back again?