Write a program in java to demonstrate JDBC?

//    set classpath=C:\oraclexe\app\oracle\product\10.2.0\server\jdbc\lib\ojdbc14.jar

//    set path=C:\Program Files (x86)\Java\jdk1.7.0\bin

import java.sql.*;

class JavaDataBase

{

      public static void main(String arg[])

      {

            try

            {

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

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

                  Statement stmt=con.createStatement();

                  ResultSet rst=stmt.executeQuery("select * from emp");

                  System.out.println("\nID" +"\t"+ "Name" +"\t\t"+ "Degree" +"\t"+ "Salary\n");

                  while(rst.next())

                        System.out.println(rst.getInt(1) +"\t"+ rst.getString(2) +"\t"+ rst.getString(3) +"\t"+ rst.getInt(4));

                  con.close();

            }

            catch(Exception e)

            {

                  System.out.println(e);

            }

      }

}

JAVA Data Base Connectivity (JDBC).PNG

, , , , ,

Leave a Reply