I can connect fine to an Oracle 11.2 database using JDBC driver and the following Java code:
import java.sql.*;
import javax.sql.DataSource;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import oracle.jdbc.OracleTypes;
...
Connection conn=null;
// connect to database
Context context = new InitialContext();
DataSource ds = (DataSource)context.lookup("jdbc/myPool");
conn = ds.getConnection();
But now I need to set the option SetFloatAndDoubleUseBinary to true. See page 4-16 here
http://docs.oracle.com/cd/E14072_01/java.112/e10589.pdf
So I try to follow examples from here:
http://docs.oracle.com/cd/E11882_01/java.112/e16548/urls.htm
and I modify the code as:
import java.sql.*;
import java.util.Properties;
import javax.sql.DataSource;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import oracle.jdbc.OracleTypes;
...
Connection conn=null;
// set connection properties
Properties info = new java.util.Properties();
info.put ("SetFloatAndDoubleUseBinary","true");
// connect to database
Context context = new InitialContext();
DataSource ds = (DataSource)context.lookup("jdbc/myPool");
conn = ds.getConnection(info);
and I'm getting the following compile error:
myClass.java:1145: cannot find symbol
symbol : method getConnection(java.util.Properties)
location: interface javax.sql.DataSource
conn = ds.getConnection(info);
^
Anyone know how I can properly set SetFloatAndDoubleUseBinary here?
UPDATE 1
Changing to:
import java.sql.*;
import java.util.Properties;
import javax.sql.DataSource;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import oracle.jdbc.OracleTypes;
import oracle.jdbc.*; // NEW
import oracle.jdbc.pool.*; // NEW
...
Connection conn=null;
// set connection properties
Properties info = new java.util.Properties();
info.put ("SetFloatAndDoubleUseBinary","true");
// connect to database
Context context = new InitialContext();
DataSource ds = (DataSource)context.lookup("jdbc/myPool");
((OracleDataSource)ds).setConnectionProperties(info); // NEW
conn = ds.getConnection(); // NEW
gives the following run time error:
stack trace: java.lang.ClassCastException: com.sun.gjc.spi.jdbc40.DataSource40 cannot be cast to oracle.jdbc.pool.OracleDataSource

DataSource. Did you try to cast theDataSourceretrieved on jndi toOracleDataSource? Ex:((OracleDataSource)ds).setConnectionProperties(info);thenconn = ds.getConnection()should return a connection with your properties correctly set.