connecting JDBC - oracle

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

Related

Can not load JDBC driver. in

Test Plan.
Add one Thread Group with default settings.
Add JDBC Connection Configuration with below setting.
Add JDBC Requset for Simple select stement.
Add Constant Timer with 5000 miliseconds Thread Delay.
Add View Results Tree.
My DBServer Name : proddbtest1.xyz.com
SQL Instance Name: Prodbtest1\LIVE
I fill up this parameter value in DB URL and Driver class. In fact I download latest JDBC sqljdbc42.jar from Net and past at Lib folder.
After running my test plan still I get an error message
"java.sql.SQLException: Cannot load JDBC driver class
com.microsoft.jdbc.sqlserver.SQLServerDriver"
Can any one help me where I am passing wrong configuration settings.
As per Using the JDBC Driver article the correct Microsoft JDBC Driver class name is:
com.microsoft.sqlserver.jdbc.SQLServerDriver
you are trying to use the following one:
com.microsoft.jdbc.sqlserver.SQLServerDriver
^^^^^^^^^^^^^^
So replace jdbc and sqlserver and your setup will work.
Also don't forget to restart JMeter to pick the sqljdbc42.jar up.
Just in case see The Real Secret to Building a Database Test Plan With JMeter article to learn more about database load testing using JMeter

Using BigQuery in DataGrip with JDBC

Has anyone been able to use the new JDBC drivers for BigQuery in JetBrains DataGrip?
I've followed the these steps
Created a driver in DataGrip with all the jar files
Created a database with a connection string with a service account file
The connection test says successful, but once I try to query something I receive an error:
java.lang.ClassNotFoundException: com.google.api.client.json.JsonFactory
I've added the following files from the Simba ZIP into the DataGrip driver:
GoogleBigQueryJDBC42.jar
jackson-core-2.1.3.jar
google-api-client-1.22.0.jar
google-api-services-bigquery-v2-rev320-1.22.0.jar
google-http-client-1.22.0.jar
google-http-client-jackson2-1.22.0.jar
google-oauth-client-1.22.0.jar
So I'm not sure what to do next. I tried changing their order in DataGrip but it didn't seem to make a different.
My connection string also looks OK I think:
jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;ProjectId=...;OAuthType=0;OAuthPvtKeyPath=...;OAuthServiceAcctEmail=...;
You may get this error when the driver JAR files are not referenced correctly in the tool. I have listed out the steps I used to connect to BigQuery via DataGrip.
Add a new driver by adding all the JAR files from the zip. The correct class name should be selected from the "Class" drop down in this step.
Add a new data source by selecting the newly created BigQuery JDBC driver. Provide the correct connection URL in this step.
If the test connection succeeds, create a new query for the same datasource.
Make sure your query uses the correct format "dataset.tablename" and is running on the data source you just tested.
For me replacing P12 with Json worked. But, cannot use DataGrip or in general JDBC to access BigQuery because of various query/incompatibility issues.
This video can be referred : https://www.youtube.com/watch?v=r9l2c_aQPoQ&ab_channel=JetBrainsTV
to use the new simba jdbc drivers for BigQuery in JetBrains DataGrip. It covers all steps one by one for working setup.
Here is the blog which refers this video: https://blog.jetbrains.com/datagrip/2018/07/10/using-bigquery-from-intellij-based-ide/
Drivers can be downloaded at : https://cloud.google.com/bigquery/providers/simba-drivers
Note: Make sure to go through comments on blog to authenticate without creating service account on gcp.
Hope this is helpful!

How can I read a .dbf file with wso2 Data Services Server?

the documentation of WSO2 Data services server say you can read any database with a JDBC driver, and I found that there are some JDBC libraries for .DBF files.
DSS documentation: http://wso2.com/products/data-services-server/
JDBC for DBF files: http://www.csv-jdbc.com/stels_dbf_jdbc.htm
Someone has already done or did something similar?
I would appreciate your help
Yes, WSO2 DSS supports any RDBMS datasource type, provided a compatible driver is copied to the product. You can follow the below steps.
You can add the JDBC driver to the $DSS_HOME/repository/component/lib folder and start the server.
Create a dataservice by following the this doc
Add an RDBMS type datasource, as DBF is not listed in the pre-defined datasource types, select 'Generic' and give the driver class name, connection url, username and password according to the DBF specified
Add query and then an operation. Our official documentation has all the necessary steps.
Please note that, we have not tested with this driver, therefore, to use in a production environment, a comprehensive testing cycle will be needed (including load tests, long running tests .. etc).

Database url in jmeter?

I have a database stored at a server. I want to load test the server using jmeter.It requires a field called database url? Now what i am supposed to fill in that?
Also it is asking for jdbc driver class? What will be the values of these two?
JMeter uses JDBC.
What is your db ? Oracle, mysql ...
Each Db provides drivers you need to put in jmeter/lib folder.
For url each driver has a syntax, examples:
http://www.petefreitag.com/articles/jdbc_urls/
Then you need to add login/password
your database url should be -jdbc:mysql://localhost:3306/
database url is the host address of the database u can see that when you connect mysql from gui using SQl yog
is the database name that you have created in mysql
Your driver class should be -com.mysql.jdbc.driver
user name and password of the database

Spring Datasource and Database Schema

I am trying to declare a Spring datasource pointing to a DB2 database. Presently I am using a org.springframework.jdbc.datasource.DriverManagerDataSource to setup the connection but am not finding any way to specify the database schema in the database in the datasource bean. Could anyone help me on this?
Problem is there is no standard way to set the schema, each database has a different mechanism.
A work around is to set the schema as part of the db url...
For db2 the url will look something like:
jdbc:db2://SERVER_NAME:PORT/DATABASE:currentSchema=SCHEMA_NAME;
hope that helps...
Special note: make sure you add the semicolon ; at the end of the URL, otherwise you will get errors saying URL is invalid. Also make sure nothing after last ; exists (not even spaces).
There isn't a means to do this with the standard Spring namespace. Rob Harrop's response to a request to add the schema to the configuration:
In general, this kind of functionality should be pushed into the connection pool since there is no really elegant and performant way to do this via a decorator. The pool can set the schema once per connection it creates, whereas here you have to set it each time a connection is retrieved.
If you're desperate to set the proxy in your configuration, the submitter included some code for a proxy to allow the schema to be specified.
If your connection uses the owner of the schema as the user then that connection will point to that particular schema.
ie. If user user1 is the owner of the database schema named schema1 then if you connect to the database using user user1 then by default the connection will point to schema1.
We have used UserCredentialsDataSourceAdapter provided by spring to connect to different schemas based on the logged in user. This provides a datasource which is pointing to a particular schema based on the user. This uses a thread based login information. Each thread has to decide to which schema it has to connect and provide the user according to that.

Resources