Oracle 10g connection with Java - java

what are the drivers which are used to connect with java for Desktop application. i have found many types like tiny and all but was not able to understand.
Please help me out

To make your life easier, I would recommend just using Oracle's Thin Driver.
First, download the driver from Oracle's site:
http://www.oracle.com/technetwork/database/features/jdbc/index-091264.html
Then add JAR to your project and connect to database using:
Class.forName ("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection
("jdbc:oracle:thin:#//localhost:1521/orcl", "scott", "tiger");
Of course, replace these parameters with the ones corresponding to your DB.

Have you looked into official site
See Also
JDBC kick start

for oracle 10g the JDBC driver is "ojdbc10_g.jar"
it is available on your system inside %ORACLE_HOME\jdbc\lib
No need to download.
Class.forName ("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection ("jdbc:oracle:thin:#//localhost:1521/orcl", "scott", "tiger");
conn.setAutoCommit(false);

The "thin" driver is a 100% java implementation. The OCI calls the C implementation. There might even be a JDBC to ODBC bridge, allowing you to use your system's ODBC driver. Suggested reading: Oracle Instant Client

The easiest one to deploy is probably the type 4 driver, or the thin driver. I say it is the easiest because it does not rely on any Oracle native libraries or client install to operate. It is readily available from Oracle.

Related

How do I connect SQL*Plus with Java using netbeans? [duplicate]

what are the drivers which are used to connect with java for Desktop application. i have found many types like tiny and all but was not able to understand.
Please help me out
To make your life easier, I would recommend just using Oracle's Thin Driver.
First, download the driver from Oracle's site:
http://www.oracle.com/technetwork/database/features/jdbc/index-091264.html
Then add JAR to your project and connect to database using:
Class.forName ("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection
("jdbc:oracle:thin:#//localhost:1521/orcl", "scott", "tiger");
Of course, replace these parameters with the ones corresponding to your DB.
Have you looked into official site
See Also
JDBC kick start
for oracle 10g the JDBC driver is "ojdbc10_g.jar"
it is available on your system inside %ORACLE_HOME\jdbc\lib
No need to download.
Class.forName ("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection ("jdbc:oracle:thin:#//localhost:1521/orcl", "scott", "tiger");
conn.setAutoCommit(false);
The "thin" driver is a 100% java implementation. The OCI calls the C implementation. There might even be a JDBC to ODBC bridge, allowing you to use your system's ODBC driver. Suggested reading: Oracle Instant Client
The easiest one to deploy is probably the type 4 driver, or the thin driver. I say it is the easiest because it does not rely on any Oracle native libraries or client install to operate. It is readily available from Oracle.

how to implement sql server connection pooling in java jdbc?

I tried to search for this but it seems the answer might now be true anymore. How can do connection pooling in java with sql server? I found the new jdbc driver of microsoft but there's no sample code to show to use it.
Microsoft MSSQL-JDBC is now open sourced. You can see test cases used Hikari & Apache DBCP connection pool.
One can see PoolingTest.java and methods testApacheDBCP and testHikariCP.
For HikariCP and DBCP

Where exactly should JDBC URL value be changed?

I'm trying to run some application and get the following error:
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for
JDBC]Can't start a cloned connection while in manual transaction mode.
I know that I should add the parameter ;SelectMethod=Cursor to your JDBC URL
But I'm having problem understanding where exactly should I change it? Should it be some conf file in JDBC driver folder somewhere? Or can I do it from sql management studio?
Also is there some easy way to determine if and what version of JDBC driver I have?
Help is very much appreciated!
You specify the URL when creating your JDBC connection, e.g.:
Connection con = DriverManager.getConnection(
"jdbc:sqlserver://[serverName[\instanceName][:portNumber]][;property=value[;property=value]]",
username,
password);
Of course you have to replace the stuff in the brackets with your values.
Quite the same is true for every other tool (e.g. IntelliJ, Eclipse) I know of that connects to a DB via JDBC. See e.g. attached screenshot. Here you also specify the connection parameters via the JDBC URL.

Connection from a Java program to a SQL Developer database

I would like to access to a Oracle database (SQL Developer) from a Java program. I never used JDBC before.
Here is what i wrote:
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc:odbc:host_name:port:database_name";
Connection con = DriverManager.getConnection(url, login, passwd);
I got an error:
[Microsoft][ODBC Driver Manager]
Data source name not found and no default driver specified
Host name, port, DB name and logins are good.
Is this driver OK to communicate with SQL Developer ?
I don't know what to do,
thanks for helping !
Try this
Class.forName ("oracle.jdbc.driver.OracleDriver");
for Oracle you can use ojdbc
Class.forName("oracle.jdbc.driver.OracleDriver");
for SQL Server u can use jtds
Class.forName("net.sourceforge.jtds.jdbc.Driver");
The JDBC driver sun.jdbc.odbc.JdbcOdbcDriver is bridge driver that wraps an ODBC driver as described here.
SQL Developer is an Oracle tool that acts as an IDE against the Oracle database.
To connect Java to an Oracle database you should obtain the Oracle JDBC driver and ensure the jar is on your classpath (as described in the documentation for java.sql.DriverManager, forcing the class to be loaded is no longer necessary).
The important bit is the connection string, which in its simplest form for Oracle should follow the structure:
jdbc:oracle:thin:#//host:port/service
Where:
host: the hostname of the machine running Oracle
port: the port that Oracle is listening for connections on
service: the database instance to connect to
The full docs are here.

ODBC Connection Setup in Java

I want to write a Java program that automates the work that the ODBC Data Source Administrator does in Windows.
That is, given an ODBC connection name and a path to the database on the hard drive, I want it to create the connection.
I really have no idea where to even begin with this. I looked at this but it said it was for C and I don't think that's very helpful. If anyone could point me in the right direction for this at all, I would appreciate it.
(I realize this question is REALLY vague, but that's all the information I was given.)
The answer to the question is that you don't need a registered DSN.
Here is an example of using a ODBC connection (not JDBC) from Java, using the system ODBC driver. Instead of editing the registry to create a registered DSN, your alternative is to use a un-registered DSN, like so:
Driver=sun.jdbc.odbc.JdbcOdbcDriver
Source=jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=C:/Dir/DB/MyDB.mdb;
Or, using SQL Server:
Driver=sun.jdbc.odbc.JdbcOdbcDriver
Source=jdbc:odbc:Driver={SQL Server};SERVER=127.1;DATABASE=MyDB;UID=sa;PWD=mypass
All ODBC configuration is in Windows registry or odbc.ini in Linux (I haven't used ODBC on other platforms). At first you must create such configuration using ODBC manager, then check what was saved in configuration and write program that do the same. If you work with Windows 32 bit, then check registry at HKEY_LOCAL_MACHINE\SOFTWARE\ODBC.
Windows 64 bit have different configurations for 32 bit apps and 64 bit apps (just look for odbc.ini string in registry).
I think Java is not the best language to change something in Windows registry, but with Java you can create .reg text file that can be imported by regedit.exe, or you can use other language like Python with win32 extensions (Active Python has it by default).
You will want to look into using JDBC.
String driver ="sun.jdbc.odbc.JdbcOdbcDriver"
String url = "jdbc:odbc:Driver={Microsoft Access Text Driver (*.txt, *.csv)};DBQ=C:/CSVFolder
query = select * from myfile.csv
Check this one out..
Java Database Connectivity (JDBC) supports ODBC-based databases and provides a independent database.
Connection connection = null;
try {
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
connection = DriverManager.getConnection("connection string", "userName", "password" );
} catch (SQLException e) {
}
return connection;
I've never had to connect to MS SQL Server before. I've always used DB2 or Derby, MYSQL and everything was always the same for creating a connection. This is what I had to do for SQL Server.
private final String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
Class.forName(driver);
url="jdbc:odbc:;DRIVER={SQL Server};SERVER="+server+","+port+";DATABASE="+dbName;
connection = DriverManager.getConnection(url,user,password);

Categories

Resources