JDBC Oracle program

JDBC Oracle program

Here is my code:

import java.sql.*;
public class Tyagi
{
    public static void main (String args[])throws SQLException
    {
        ResultSet rs;
        try
        {
        Class.forName("oracle.jdbc.driver.OracleDriver");
        Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:8080:oracle", "System", "System");
        Statement st = conn.createStatement();
        rs=st.executeQuery("Select * from brendon");
        while(rs.next())
            System.out.println(rs.getString(1));
        st.close();
        conn.close();
        }
        catch(Exception e)
        {
        System.out.println(e);
        }
    }
}

i have found exception in the code that is java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver

View Answers

May 25, 2013 at 12:31 AM

use this code

import java.sql.Connection;

import java.sql.Statement;

import java.sql.ResultSet;

import java.sql.DriverManager;

public class DemoForYou

{

public static void main(String[] args) throws Exception

{

//Establish the connection between java application and 
database software

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

//Register Driver with DriverManager service

Connection con=DriverManager.getConnection("jdbc:odbc:give your dsn","username","password");

//Send and execute query in database s/w

Statement st=con.createStatement();

//process the result

ResultSet rs=st.executeQuery("select * from stduent");

while(rs.next())

System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getString(3));

//close the jdbc objects

rs.close();

st.close();

con.close();

}//main

}//class

query of the application

SQL>create table student(sid number,sname varchar2(20),sadd varchar2(20));

table created

SQL> insert into student values(101,jack,hyderabad);
1 row updated


here 101=getInt(1)

     jack=getString(2)

     hyderabad=getString(2)

Ads









Related Tutorials/Questions & Answers:
JDBC Oracle program
JDBC Oracle program  Here is my code: import java.sql.*; public class Tyagi { public static void main (String args[])throws SQLException... = DriverManager.getConnection("jdbc:oracle:thin:@localhost:8080:oracle", "System", "System
Oracle - JDBC
Oracle  How to Use Blob and Clob Data types in Oracle...  Hi friend BLOB : Binary Large Object CLOB : Character Large Object Default storage each time a BLOB or CLOB exceeds 4000 bytes you could cause
Advertisements
jdbc oracle connectivity problem
jdbc oracle connectivity problem  Hi All, I am trying to connect my swing application to oracle DB . but class.forname is giving error. Please suggest me if there is some different way to connect swing application to oracle
jdbc program
jdbc program   Write a program to update the salaryRs.6000/- for an employee name like ‚??P. Ramu‚?? using prepared statement
servlet program for data store in oracle?
servlet program for data store in oracle?  how to store data in oracle through servlet program
Jdbc and Socket Program - JDBC
Jdbc and Socket Program  Sir, I would like to get a program i... in a database.Now we create another program 4 client-server such that the sever's database is updated everytime we enter username and password in client program
JDBC Connection code to connect servlet with oracle.
JDBC Connection code to connect servlet with oracle.  JDBC Connection code to connect servlet with oracle
REQ for connection b/w jdbc and oracle database
REQ for connection b/w jdbc and oracle database    REQ for connection b/w jdbc and oracle database    The Java classes to connect to Oracle are contained in the Oracle JDBC driver jar file. For recent releases
Java Barcode Program with Oracle database
Java Barcode Program with Oracle database  Hi Everyone, I need help to develop my new project, am going to do with barcode s/w, am very new... no and serial no of the item being scanned to Oracle 10g database. I dont have any
oracle insert statement error - JDBC
oracle insert statement error  hi.. please help me to insert a image into oracle 11g database and please say me how can i insert image from directory like G:\imagefolder\ultrasoundimage\02us02.jpeg please help me
execution of a jdbc program
execution of a jdbc program  how to execute a servlet program that..uses a jdbc driver (i.e. using mysql-connector -java )to connect to mysql in windows *PLS provid the execution steps in detail THANK YOU
Jdbc connectivity in java to oracle for retrieving data between two dates
Jdbc connectivity in java to oracle for retrieving data between two dates  Dear Sir, I Need a program in which i want to retrieve the data b/w two... am using the oracle. please help. thankyou sir
How Jdbc program can be run??
How Jdbc program can be run??  import java.sql.*; import java.util.... { Connection conn=DriverManager.getConnection("jdbc:odbc:advdsn1","student","myself... created successfully and when i compiled this program then it compiled successfully
how to run jdbc program in linux-ubuntu?
how to run jdbc program in linux-ubuntu?   how to run jdbc program in linux-ubuntu
how to run jdbc program in linux-ubuntu?
how to run jdbc program in linux-ubuntu?  how to run jdbc program in linux-ubuntu?   hi firstly download the jdk on your system using... to compile java program javac prog.java java prog
write a program for complete JDBC based application
write a program for complete JDBC based application   thank you sir giving answer for my question. my another question is: Write a complete JDBC... and the program should have the facilities of Adding, Modifying, Viewing and Deleting
Benefit of Spring Injection over Hibernate / JDBC w/Oracle
Benefit of Spring Injection over Hibernate / JDBC w/Oracle  Im new to Spring and am still trying to understand the advantages over using jdbc (I understand that Spring offers more than just db connectivity but focusing specificly
oracle
oracle   sir now am doing one project , my frond end is vb and backend is oracle. so 1> how can i store the image in my field 2> how can i back up the table into .txt file
passing xml created using DocumentBuilderFactory as input to oracle stored procedure using java JDBC
and it is to be send using JDBC. Stored procedure in oracle database will contains two... = DriverManager.getConnection("jdbc:oracle:thin:@10.100.23.155:1521:WNPG", "WEBSERVICE", "WEBSERVICE... passing xml created using DocumentBuilderFactory as input to oracle stored
hi, Everyone ,i'm learning jdbc, i got an nullpointerexception when execute this program.
class=oracle.jdbc.driver.OracleDriver url=jdbc:oracle:thin:@localhost:1521:xe user...hi, Everyone ,i'm learning jdbc, i got an nullpointerexception when execute this program.   ConnectionProvider.java import java.util.*; import
Oracle Database connectivity probem
also set the environment variable like that .;E:\oracle\ora81\jdbc\lib\classes12.zip;E:\oracle\ora81\jdbc\lib\ojdbc14.zip;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\servlet-api.jar;E:\oracle\ora81\jdbc\lib\classes111.zip I
oracle connectivity
oracle connectivity  con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","hr","hr"); i have error on above line when i tried...=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","hr","hr
jdbc
oracle.jdbc.driver.OracleDriver()); Connection con=DriverManager.getConnection("jdbc:oracle:thin
jdbc
jdbc   how to write program to save data and retrieve data from the form in Java
Jdbc
Jdbc  A java program with jdbc connectivity with insert,delete,update options for name,regno,mark1,mark2,total
JDBC
JDBC  why we use batch in jdbc
jdbc
jdbc  display the records using index in jdbc
jdbc
jdbc  Hai , Give a steps for jdbc connectivity
jdbc
jdbc  I can't run my jdbc program because it has error in this line: public static void main(String[] args) the error is:illegal static declaration in inner class would you please let me whats the problem? regards
jdbc
jdbc  how to update int values of ms-access in jdbc program?   In MS Access database, use Number data type for int values. import... =DriverManager.getConnection("jdbc:odbc:access","",""); Statement st=null; st
JDBC
JDBC  How to add set of queries in a single query in JDBC

Ads