java- jdbc with type 4 driver

java- jdbc with type 4 driver

My program code is-----

import java.sql.*; import java.lang.* ; import java .io.*; import java.util.*; import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.SQLException;
import oracle.jdbc.pool.OracleDataSource;

class Jdbcthin { public static void main(String arr[]) throws SQLException, ClassNotFoundException { try { Class.forName("oracle.jdbc.driver.OracleDriver");

        Connection con = DriverManager.getConnection("jdbc:oracle:thin@localhost:1521:XE", "system", "oracle");

    Statement stmt = con.createStatement();
        ResultSet rs = stmt.executeQuery("select*from Emp");
        System.out.println("Following Records are fetched");
        while(rs.next())
        {

System.out.println(rs.getInt(1) +"\t\t"+ rs.getString(2)+"\t\t"+ rs.getString(3)+"\t\t"+ rs.getInt(4)); } con.close(); } catch(Exception e) { System.out.println(e); } } }

It is giving an error like--

import java.sql.*; import java.lang.* ; import java .io.*; import java.util.*; import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.SQLException;
import oracle.jdbc.pool.OracleDataSource;

class Jdbcthin { public static void main(String arr[]) throws SQLException, ClassNotFoundException { try { Class.forName("oracle.jdbc.driver.OracleDriver");

        Connection con = DriverManager.getConnection("jdbc:oracle:thin@localhost:1521:XE", "system", "oracle");

    Statement stmt = con.createStatement();
        ResultSet rs = stmt.executeQuery("select*from Emp");
        System.out.println("Following Records are fetched");
        while(rs.next())
        {

System.out.println(rs.getInt(1) +"\t\t"+ rs.getString(2)+"\t\t"+ rs.getString(3)+"\t\t"+ rs.getInt(4)); } con.close(); } catch(Exception e) { System.out.println(e); } } }

It giving an error like this----

import java.sql.*; import java.lang.* ; import java .io.*; import java.util.*; import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.SQLException;
import oracle.jdbc.pool.OracleDataSource;

class Jdbcthin { public static void main(String arr[]) throws SQLException, ClassNotFoundException { try { Class.forName("oracle.jdbc.driver.OracleDriver");

        Connection con = DriverManager.getConnection("jdbc:oracle:thin@localhost:1521:XE", "system", "oracle");

    Statement stmt = con.createStatement();
        ResultSet rs = stmt.executeQuery("select*from Emp");
        System.out.println("Following Records are fetched");
        while(rs.next())
        {

System.out.println(rs.getInt(1) +"\t\t"+ rs.getString(2)+"\t\t"+ rs.getString(3)+"\t\t"+ rs.getInt(4)); } con.close(); } catch(Exception e) { System.out.println(e); } } }

it producing an error like---

java.sql.SqlException : Invalid Oracle URL Specified

Please tell me its solution..

Thanks..

View Answers

July 13, 2011 at 2:30 PM

Follow these steps:

1) Import the following packages in your java file:***

import java.sql.*;
import oracle.jdbc.driver.*;
import oracle.sql.*;

2) Load and Register the JDBC driver:***

DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

or you can use

Class.forName("oracle.jdbc.driver.OracleDriver");

3) Connect to database:***

a) If you are using oracle oci driver,you have to use:

Connection conn = DriverManager.getConnection("jdbc:oracle:oci8:
@oracle.world", "root", "root");

where oracle.world is the TNSNAMES entry and root is the username and password.

b) If you are using oracle thin driver,you have to use:

Connection conn = DriverManager.getConnection ("jdbc:oracle:thin:@localhost:3306:roseindia",
"root", "root");

where localhost is the host,3306 is the port, roseindia is the database and root is the username and password.

4) Querying the database:**

a)create statement:

Statement st = conn.createStatement();

b)write query and execute the query:

ResultSet rs = st.executeQuery("SELECT * from student");

5) Close the statement,resultset and connection:**

rs.close();
st.close();
conn.close();

Try the following code:

import java.sql.*;
import oracle.sql.*;
import oracle.jdbc.driver.*;

public class OracleExample {
public static void main (String[] args) {
try{
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Connection conn = DriverManager.getConnection("jdbc:oracle:thin: @localhost:3306:Oracle", "rose", "rose");
Statement st = conn.createStatement();
ResultSet rs = sql_stmt.executeQuery("SELECT * from student");
String str = "";
while (rs.next())
{
System.out.println(rset.getInt(1)+" "+ rs.getString(2)+" "+ rset.getFloat(3)+"\n";
}
rs.close();
st.close();
conn.close();
}
catch(Exception e){}
}
}









Related Tutorials/Questions & Answers:
java- jdbc with type 4 driver
java- jdbc with type 4 driver  My program code is----- import java.sql.*; import java.lang.* ; import java .io.*; import java.util.*; import... and Register the JDBC driver:*** DriverManager.registerDriver(new
type 4 jdbc driver
type 4 jdbc driver   i read in this site that type 4 jdbc driver is the fastest one so used it to connect with the database.......but not tried another drivers,....can u specifically answer me why type 4 is the fastest one
Advertisements
Jdbc connectivity by type 4 driver
Jdbc connectivity by type 4 driver  I have done a code with database connectivity with driver 4,it copiles,but while running it is showing...=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521","system","123
type 4 drivers - JDBC
type 4 drivers  Hi! What is the syntax for Type - 4 drivers. give me any sample code. Thanks in advance..  Hi Friend, Please visit the following link: http://www.roseindia.net/jdbc/jdbc-driver-and-its
Fastest type of JDBC Driver
Fastest type of JDBC Driver  hello, What is the fastest type of JDBC driver?   hii,ADS_TO_REPLACE_1 Type 4 is the fastest JDBC driver
fastest type of JDBC driver
fastest type of JDBC driver  What is the fastest type of JDBC driver
Java JDBC driver
Java JDBC driver  What is JDBC Driver
Jdbc Driver - JDBC
-ODBC Driver)Type 2(java native driver)Type 3Type 4  Type of JDBC..., partly Java driver, also called Type 2. * JDBC-Net, pure Java driver, also called Type 3. * Native-protocol, pure Java driver, also called Type 4.For JDBC
Disabling contextual LOB creation as JDBC driver reported JDBC version [3] less than 4
Disabling contextual LOB creation as JDBC driver reported JDBC version [3] less than 4  Hi, In my Hibernate application following error is coming: Disabling contextual LOB creation as JDBC driver reported JDBC version [3] less
Which JDBC Type Using - Java Beginners
Which JDBC Type Using  As there are 4 types of JDBC driver. I wanted to know: How would one come to know that which jdbc type any web application... friend, Read for more information. http://www.roseindia.net/jdbc
Java JDBC driver
Java JDBC driver  What are the different JDBC drivers available
jdbc driver for mysql - Java Beginners
jdbc driver for mysql  I need jdbc driver program for connecting java progrma to mysql. Please any one send me the url to download the driver... of jdbc-mysql database connectivity and idea about jdbc and mysql driver
java run time error in loading the driver - JDBC
java run time error in loading the driver  when i mrunning the program in oracle using type 4 driver it is giving the error as Error... JDBC driver's JAR file in your classpath and check it Thanks
JDBC driver is the fastest one
JDBC driver is the fastest one  Which type of JDBC driver is the fastest one
jdbc driver
jdbc driver  hello, can we create a own jdbc driver? how can we create
no driver - JDBC
{ try { //Loads Type 2 Driver Class.forName...()); System.exit(1); } /* Type 2 driver url */ //String url... the program: run: SQL Exception: No suitable driver found for jdbc:db2
JDBC Driver - JDBC
JDBC Driver  What are the diffrent types of JDBC driver
How to Retrieve Excel data into mysql using type 2 JDBC-ODBC driver
How to Retrieve Excel data into mysql using type 2 JDBC-ODBC driver  ... type 1 driver and i have done successfully.but disadvantage is when i create... Sources(ODBC) Open User DSN tab Add a user DSN Select Microsoft Excel Driver
JDBC Driver and Its Types
for Java JDBC driver is a Type 4 JDBC driver, indicating that the API is a pure...-API, partly Java driver, also called Type 2. JDBC-Net, pure Java driver... 4. Type 1 Driver- the JDBC-ODBC bridge The JDBC
Product Components of JDBC
. The JDBC Driver Manager. 3. The JDBC Test Suite. 4. The JDBC-ODBC Bridge.ADS... important class that defines objects which connect Java applications to a JDBC driver... of  Java Platform Enterprise Edition (J2EE).  4. The JDBC-ODBC
Best JDBC Driver and Why - JDBC
Best JDBC Driver and Why   Hi Friends , In JDBC 4 drivers are there among this which is best and why. which driver is most commonly used in web application
What is JDBC Driver ?
What is JDBC Driver ?  What is JDBC Driver
JDBC Driver interface
JDBC Driver interface  What is JDBC Driver interface
MySQL Driver for JDBC - JDBC
MySQL Driver for JDBC  Sir, I have started reading your JDBC tutorial...... Example."); Connection conn = null; String url = "jdbc:mysql://localhost:3306   Hi,Please download the driver from http://www.mysql.com/products/connector
Confused in driver - JDBC
Confused in driver  I am confused about the concept Driver in JDBC. Although i know jdbc very well(in respect... mean to say theoretically it is not cleared please explain me the type of driver... of some picture i want o know
JDBC Driver
JDBC Driver  I want to know the clear syntax and usages of $ types of JDBC drivers. Where can i get it? I search for it, nobody give Syntax for tat different drivers. can u give a sample codes for tat
Connecting to the Database Using JDBC and Pure Java driver
Connecting to the Database JDBC Driver In our search... earlier MM.MySQL Driver is 100% pure Java Driver for MySQL... this driver to make connections to MySQL server from both Java
Java JDBC
Java JDBC  What is the fastest type of JDBC driver
Set properties for a JDBC driver
Set properties for a JDBC driver  How do I set properties for a JDBC driver and where are the properties stored
How to download MySQL JDBC driver?
How to download MySQL JDBC driver?  Hi, What is JDBC Driver? How to download MySQL JDBC driver? Thanks   Hi, JDBC - Java database... program. To connect to MySQL database from Java program we need JDBC Driver of MySQL
What is the return type of execute mehtod in jdbc - Java Beginners
. My interview asked wat is return type of execute() in jdbc . should...What is the return type of execute mehtod in jdbc  Hi Deepak, u posted this answer. " Whatever it may be the statement type, like
jdbc type-4 driver
jdbc type-4 driver  I was tried the code that you give to run type-4 driver . import java.sql.*; import oracle.jdbc.driver.*; import oracle.sql.*; while compiling the error was like: package oracle.jdbc.odbc.driver does
maven mysql jdbc driver
maven mysql jdbc driver  How to add the maven mysql jdbc driver dependency in the pom.xml file of a maven based application?   Hi, Its simple!! Add the following into your pom.xml file: <dependency> <
JDBC Video Tutorial: How to download JDBC Driver for MySQL?
is JDBC Type 4 database driver, which directly connects to the default (specified...First thing to develop the JDBC program is to download the JDBC Driver... the MySQL database, so we have download the JDBC Driver for the MySQL
Maven dependency for com.qwazr - jdbc-cache-driver version 1.2 is released. Learn to use jdbc-cache-driver version 1.2 in Maven based Java projects
use this version ( com.qwazr - jdbc-cache-driver version 1.2 ) in their Java...Maven dependency for  com.qwazr  - Version 1.2 of jdbc-cache-driver released The developers of   com.qwazr - jdbc-cache-driver project
Maven dependency for com.navercorp.pinpoint - pinpoint-informix-jdbc-driver-plugin version 2.5.0 is released. Learn to use pinpoint-informix-jdbc-driver-plugin version 2.5.0 in Maven based Java projects
-jdbc-driver-plugin version 2.5.0 ) in their Java project if it is based on Maven... - pinpoint-informix-jdbc-driver-plugin version 2.5.0 in Java projects. Follow... of pinpoint-informix-jdbc-driver-plugin released The developers of  
Maven dependency for com.navercorp.pinpoint - pinpoint-informix-jdbc-driver-plugin version 2.4.2 is released. Learn to use pinpoint-informix-jdbc-driver-plugin version 2.4.2 in Maven based Java projects
-jdbc-driver-plugin version 2.4.2 ) in their Java project if it is based on Maven... - pinpoint-informix-jdbc-driver-plugin version 2.4.2 in Java projects. Follow... of pinpoint-informix-jdbc-driver-plugin released The developers of  
Maven dependency for com.navercorp.pinpoint - pinpoint-informix-jdbc-driver-plugin version 2.4.1 is released. Learn to use pinpoint-informix-jdbc-driver-plugin version 2.4.1 in Maven based Java projects
-jdbc-driver-plugin version 2.4.1 ) in their Java project if it is based on Maven... - pinpoint-informix-jdbc-driver-plugin version 2.4.1 in Java projects. Follow... of pinpoint-informix-jdbc-driver-plugin released The developers of  
Maven dependency for com.navercorp.pinpoint - pinpoint-informix-jdbc-driver-plugin version 2.4.0 is released. Learn to use pinpoint-informix-jdbc-driver-plugin version 2.4.0 in Maven based Java projects
-jdbc-driver-plugin version 2.4.0 ) in their Java project if it is based on Maven... - pinpoint-informix-jdbc-driver-plugin version 2.4.0 in Java projects. Follow... of pinpoint-informix-jdbc-driver-plugin released The developers of  
Maven dependency for com.navercorp.pinpoint - pinpoint-informix-jdbc-driver-plugin version 2.3.0 is released. Learn to use pinpoint-informix-jdbc-driver-plugin version 2.3.0 in Maven based Java projects
-jdbc-driver-plugin version 2.3.0 ) in their Java project if it is based on Maven... - pinpoint-informix-jdbc-driver-plugin version 2.3.0 in Java projects. Follow... of pinpoint-informix-jdbc-driver-plugin released The developers of  
Maven dependency for com.navercorp.pinpoint - pinpoint-informix-jdbc-driver-plugin version 2.3.3 is released. Learn to use pinpoint-informix-jdbc-driver-plugin version 2.3.3 in Maven based Java projects
-jdbc-driver-plugin version 2.3.3 ) in their Java project if it is based on Maven... - pinpoint-informix-jdbc-driver-plugin version 2.3.3 in Java projects. Follow... of pinpoint-informix-jdbc-driver-plugin released The developers of  
Maven dependency for com.navercorp.pinpoint - pinpoint-informix-jdbc-driver-plugin version 2.3.1 is released. Learn to use pinpoint-informix-jdbc-driver-plugin version 2.3.1 in Maven based Java projects
-jdbc-driver-plugin version 2.3.1 ) in their Java project if it is based on Maven... - pinpoint-informix-jdbc-driver-plugin version 2.3.1 in Java projects. Follow... of pinpoint-informix-jdbc-driver-plugin released The developers of  
Maven dependency for com.navercorp.pinpoint - pinpoint-informix-jdbc-driver-plugin version 2.4.0-RC1 is released. Learn to use pinpoint-informix-jdbc-driver-plugin version 2.4.0-RC1 in Maven based Java projects
-informix-jdbc-driver-plugin version 2.4.0-RC1 ) in their Java project...; com.navercorp.pinpoint - pinpoint-informix-jdbc-driver-plugin version 2.4.0-RC1 in Java... - pinpoint-informix-jdbc-driver-plugin version 2.4.0-RC1 java library in your project
Maven dependency for com.navercorp.pinpoint - pinpoint-informix-jdbc-driver-plugin version 2.3.2 is released. Learn to use pinpoint-informix-jdbc-driver-plugin version 2.3.2 in Maven based Java projects
-jdbc-driver-plugin version 2.3.2 ) in their Java project if it is based on Maven... - pinpoint-informix-jdbc-driver-plugin version 2.3.2 in Java projects. Follow... of pinpoint-informix-jdbc-driver-plugin released The developers of  
Driver Manager Class
; The JDBC Driver Manager The JDBC Driver Manager... to a JDBC driver. Usually  Driver Manager is the backbone of the JDBC... of managing the different types of JDBC database driver running on an application
Frameworks and example source for writing a JDBC driver.
Frameworks and example source for writing a JDBC driver.  Where can I find info, frameworks and example source for writing a JDBC driver
JDBC 4 Features, JDBC 4.0 Features
.style1 { margin-left: 40px; } JDBC 4 Features In this section we are discussing about the new features of JDBC 4.0. Jdbc 4.0 ships with Java SE 6..., SQL XML data type etc. Here are some features of jdbc 4.0ADS_TO_REPLACE_1 1
Version of com.qwazr>jdbc-cache-driver dependency
List of Version of com.qwazr>jdbc-cache-driver dependency
Features of JDBC 4.0
Auto- loading of JDBC driver class: In JDBC 4 invoking the getConnection... Features of JDBC 4.0       JDBC 4... productivity.  JDBC 4's key priority is to make it easier for developers to work
JDBC - JDBC
of JDBC drivers available. They are:Type 1 : JDBC-ODBC Bridge Driver A JDBC-ODBC... Java technology-enabled driver converts JDBC calls into calls on the client API... middleware products.Type 4: JDBC Net pure Java DriverA native-protocol fully Java

Ads