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
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>
<
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
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
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
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
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-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
Understanding the JDBC Architecture
; databases.
Type 3
JDBC Architecture
Type 4 Java to Database....)
Type 1
JDBC Architecture
Type 2
Java to Native API.
Type... Architecture
Type 3
Java to Network Protocol Or All-
Java Driver.
Type 3
jdbc - JDBC
Loading
JDBC driver at runtime How to load
JDBC Driver at runtime
Driver
Driver can u send type4
jdbc driver class name and url for microsoft sql server 2008
Type casting in java
Type casting in
java
In this section you will learn about
type casting in
java.
Type casting is to
convert one
type to another
type.
Java support two types... a double
type cast to int type
Reference
type casting : In
java type