I have the following code:
OracleDataSource ods = new OracleDataSource();
ods.setURL(thinConnectionString);
OracleConnection conn = (OracleConnection) ods.getConnection();
ArrayDescriptor d = ArrayDescriptor.createDescriptor("MDSYS.RDF_MODELS", conn);
When I run this code from outside Oracle's VM it works without a problem. However, when I load it on the Oracale Database JVM with loadjava tool and then run it inside Oracle, I get the following exception:
java.lang.ClassCastException
at oracle.jdbc.driver.PhysicalConnection.putDescriptor(PhysicalConnection.java)
at oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:156)
at oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:123)
at oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:106)
at oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:73)
at XercesTest.Test1(XercesTest.java:46)
at XercesTest.Test(XercesTest.java:171)
What is causing this problem and how to possibly fix it?
Edit:
When I inspect the underlying type of the connection object, I get the type oracle.jdbc.driver.T4CConnection when running outside Oracle's VM, and oracle.jdbc.driver.T2SConnection when running on the server.
Edit 2: [SOLVED]
The issue was due to conflict in the jdbc driver classes; loadjava loaded accidentally dependency files from ojdbc5.jar to the database wich caused conflit with those of Oracle. Once I dropped these, everything worked fine.
Where does the OracleDataSource and OracleConnection classes come from? Have you tried to get the connection just by using "standard JDBC classes"?
Connection conn = DriverManager.getConnection("jdbc:default:connection")
It seems that your data source connection is not that what the Oracle driver expects.
Have you changed the JDBC URL accordingly?
Do other operations fail as well, or is it just the ArrayDescriptor?
Related
I have developed a code which connects to Oracle DB using the JDBC connection string oracle.jdbc.OracleDriver & respective jar for the same.
However my customer moved to a different DB called 'Exadata' recently.
My question is since they are from same vendor 'Oracle' is there any change in the JDBC driver & JDBC connection string to Exadata DB.
Google didn't help much & instead confused me.
Any leads would be appreciated with a URL to the source as well if possible. :)
Thanks!
Exadata is a "regular" Oracle database running on specialized hardware.
There is nothing you need to change in your application.
If they redefine the database service name in tnsnames.ora, they could reuse the code without changing the URL/connect-string.
I have a oracle dataadapter that is a datasource on jasperserver.
But when I create a report using this adapter, it does not preview or fill the report on Jaspersoft Studio and JasperReports Server. Is there anyway I can create a new oracle dataadapter for testing purposes. I have downloaded odjc7.jar. But when I create a driver path to this file. I recieve a error Reason:java.sql.SQLRecoverableException: IO Error: Unknown host specified
Any details to whether oracle datasource can fill reports would be much appreciated and any details to creating a new oracle dataadapter.
If your link is correct and already works on other pcs/servers, then the error is in the connection to the database.
Check your connection to the database. Open a SQL-Developer tool and try to connect to the database.
Check if you really did add the driver to the data adapter:
It should look like this:
If you didn't provide the right driver it will not work!
Recheck your ojdbc7.jar. Maybe download it again from an official source. Also sometimes the ojdbc7.jar leads to some unknown errors. At a Jaspersoft Roadshow they recommended to still use the ojdbc6.jar.
I am a new user to Hive and have just started using it for a project. I am having problem connecting to the database using java. It is explained as follows:
I ran Hive database on my machine that created a derby metastore_db using the Embedded Derby Driver. Now, I wish to query this metastore_db via a separate Java program for issuing queries.
I followed multiple tricks that I could find online but still am not able to get that working.
Snapshot of my Java file:
String url = "jdbc:derby:metastore_db;create=true";
String username = "APP";
String password = "mine";
String drivername = "org.apache.derby.jdbc.EmbeddedDriver";
Connection con = DriverManager.getConnection(url,username, password);
Statement stmt = con.createStatement();
res = stmt.executeQuery("describe " + tableName);
Running the java file:
I have placed it in the same folder as the metastore_db and then running it using the following command:
java -cp "derby-10.4.2.jar:." ConnectTesting
I get the following syntax exception:
java.sql.SQLException: Syntax error: Encountered "describe" at line 1, column 1.
Some of the things I have already tried:
url = "jdbc:derby:metastore_db;create=false";
url = "jdbc:derby://localhost:10000/metastore_db";
url = "jdbc:derby://localhost:1527/metastore_dbDB"; // By default port at which hive listens
The above two give error as:
No suitable driver found for jdbc:derby://localhost:10000/metastore_db
url = "jdbc:derby:<full_path_to_db>/metastore_db";
If I have my HIVE server already running, and then from another terminal I execute the java file, it says:
"Another instance of Derby may have already booted the database "
Can anyone kindly point out as to what am I doing wrong and how can I connect to the already existing database to issue queries.
That's a lot of different questions. Which one do you really need answered?
"describe" is a command implemented by the "ij" tool; it is not a SQL statement. So to run "describe", you have to run it from "ij" (or by using the RunScript utility to run "ij" within your application; you cannot run it directly from Statement.executeQuery().
In order to use the client-server driver, with the hostname:port syntax, you have to (a) use the derbyclient.jar rather than the derby.jar in your classpath, and (b) have the Network Server running.
And, you cannot have the same Derby (embedded) database open in multiple applications simultaneously, so while your application is running, you cannot run a second application against the same (embedded) database. If you need this functionality, you need to switch all your applications to using the client driver, and run the Network Server to provide multi-application access to your database.
Have you run the Derby tutorial yet? It covers most of these topics in more detail: http://db.apache.org/derby/docs/10.10/getstart/
Hi guys:)
I am new to servlet.I dont know how to connect oracle database to the servlet application. Can anyone paste Oracle JDBC coding
Register Database Connection parameters:
To include your application specific connection parameters of your database, edit the file data-sources.xml under \config directory. Add the following lines to create a data source. Change the hostname, port, username/password, database name, driver type to suit your application. Make changes for url after # symbol. Save the file. This will register the data-source which can be used across your application.
<data-source
class="oracle.jdbc.pool.OracleConnectionPoolDataSource"
name="ifso817DS"
location="jdbc/Loneifso817DS"
xa-location="jdbc/xa/ifso817XADS"
ejb-location="jdbc/Pooledifso817DS"
url="jdbc:oracle:thin:#insn104a.idc.oracle.com:1521:ifso817"
connection-driver="oracle.jdbc.driver.OracleDriver"
username="travel"
password="travel"
inactivity-timeout="30"
/>
That is taken from: http://www.oracle.com/technology/sample_code/tech/java/servlets/samples/TravelServlet/Readme.html
There are a lot of articles discussing this, but I'll give you the basic steps:
download Oracle JDBC driver from Oracle's homepage, it's called ojdbc6.jar if you're using Java 6
make sure your application can find it on its classpath
since you are using servlets, you're also using a Java application server; read relevant documentation about setting up a JNDI binding to your database (usually this binding will be called jdbc/connectionName)
inside of your application, use this code:
Context ctx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup("jdbc/connectionName");
Connection conn = ds.getConnection();
This should be enough to get you started.
For more information, Google is your friend. Check out Wikipedia's JDBC page. Google "Oracle JDBC connection" for more info.
One thing that might give you headaches if you've never done stuff like this: when defining Oracle's URL for your app. server, it's format is as follows:
jdbc:oracle:thin:[user/password]#[host][:port]:SID
So you have to substitute appropriate values when defining the connection for a JNDI binding.
check this http://www.java2s.com/Code/Java/Servlets/JDBCandServlet.htm. You need to modify driver class name and connection url to connect to Oracle DB. Check http://www.java2s.com/Code/Java/Database-SQL-JDBC/OracleJDBCDriverload.htm for Oracle DB connection details
I have some Java code that uses JDBC to execute a "CREATE PROCEDURE" statement on a SQL Server 2008 instance. The create proc is failing due to an error ("Implicit conversion from data type xml to varchar(max) is not allowed. Use the CONVERT function to run this query.").
This error is not being raised to the JDBC client and so I have no indication that the sproc creation failed. As far as the JDBC statement and connection are concerned, after executing the CREATE PROC statement, there were no problems.
So does anyone know how to detect this problem from the JDBC client?
TIA!
I discovered that using PreparedStatement rather than Statement gets sproc compilation warnings raised as SQLExceptions.