java- jdbc with type 4 driver

Ads
 

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:[email protected]: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:[email protected]: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:[email protected]: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){}
}
}

Ads









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
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
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
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
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
JDBC Video Tutorial: How to download JDBC Driver for MySQL?
for downloading the JDBC Driver. This database driver is JDBC Type 4 database driver... packaged JDBC driver for connecting the Java program to the MySQL Database...First thing to develop the JDBC program is to download the JDBC Driver
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> <
Java Jdbc
oracle.jdbc.driver.*; import oracle.sql.*; 2) Load and Register the JDBC driver...Java Jdbc  sir i want to databse(oracle 10g)connectivity through java through program   Hi Friend, Follow these steps: 1) Import
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.0 1. Auto loading
Version of com.qwazr>jdbc-cache-driver dependency
List of Version of com.qwazr>jdbc-cache-driver dependency
Java JDBC
Java JDBC  How to make pagination using JDBC
Video Tutorial: How to download JDBC from MySQL?
Java driver Type 4: It denotes the pure Java/Native protocol driver For more... JDBC driver for mysql. The following steps shall guide you to a successful... file Here is the video tutorial of "How to download JDBC Driver
Java - JDBC
Java  How to Connect the java with oracle by using type2 driver? can you tell me the steps
MySQL JDBC Driver pom dependency code
MySQL JDBC Driver pom dependency code  Hi, What is the POM dependency code for MySQL's latest JDBC Driver? I can download the MySQL driver from mysql website but I need to use it in a application which is based on Maven 3
how to set fetch size for jdbc odbc driver
size for the JDBC ODBC driver and how can i fetch a set of results for JDBC ODBC driver?   Fetching results JDBC ODBC Driver A. The default fetch.... To fetch small number of rows from database, JDBC driver is designed so
the JDBC Driver has been forcibly unregistered
the JDBC Driver has been forcibly unregistered  Hi my application... application was st opped. To prevent a memory leak, the JDBC Driver has been... the web application was stopped. To prevent a memory leak, the JDBC Driver has been
No suitable driver found for jdbc:mysql://localhost:3306/TEST
No suitable driver found for jdbc:mysql://localhost:3306/TEST  hii, I.... ava.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/TEST...) the normal java project without server was working fine but in web project its
java - JDBC
is a wrapper around a primitive data type. It represents primitive data types in their corresponding class instances e.g. a boolean data type can be represented as a Boolean class instance. All of the primitive wrapper classes in Java
Maven Dependency jdbc-cache-driver >> 1.1
You should include the dependency code given in this page to add Maven Dependency of com.qwazr >> jdbc-cache-driver version1.1 in your project
Maven Dependency jdbc-cache-driver >> 1.0
You should include the dependency code given in this page to add Maven Dependency of com.qwazr >> jdbc-cache-driver version1.0 in your project
Specified JDBC Driver com.mysql.jdbc.Driver could not be loaded
Specified JDBC Driver com.mysql.jdbc.Driver could not be loaded  Hi... failedorg.hibernate.service.classloading.spi.ClassLoadingException: Specified JDBC Driver... by: org.hibernate.service.classloading.spi.ClassLoadingException: Specified JDBC Driver
JDBC-Odbc Connection
; JDBC-ODBC Connection is a JDBC driver that translates the operation in  JDBC into ODBC. For ODBC,it is a normal java application program. This bridge... in explaining JDBC Odbc Connection in Java. The code explains you a how creation
eraser type generics in java
eraser type generics in java  Explain eraser type generics in java with example
Accessing database with JDBC via Java
with JDBC via Java application?   Accessing database with JDBC through Java JDBC Example to access Database import java.sql.*; public class JdbcConnect... string type value (driver) after that matches class with given string
Java type casting
Java type casting  Can a Byte object be cast to a double value
Specified JDBC Driver com.mysql.jdbc.Driver could not be loaded
Specified JDBC Driver com.mysql.jdbc.Driver could not be loaded  Hi... failedorg.hibernate.service.classloading.spi.ClassLoadingException: Specified JDBC Driver... by: org.hibernate.service.classloading.spi.ClassLoadingException: Specified JDBC Driver
How To Use Database Driver
to interact with database. In JDBC there are four types Database driver Type 1: JDBC-ODBC Bridge driver Type 2: Native-API/partly Java driver Type 3: AllJava/Net-protocol driver Type 4: All Java/Native-protocol driver Each

Ads