Home TechnologyProgrammingSQL & Databases Subscribe to RSS

How Can You Establish A Connection To The Database?

Answer Question

1 Answer - Sort by: Date | Rating

    if you are using java and oracle then by using 'thin' driver you can do a connection......

    the following are the steps:-

    import java.io.*;
    import java.sql.*;

    class Contest
      {
        public static void main(String args[])throws SQLException
    {
        try
    {
       Class.forName("oracle.jdbc.driver.OracleDriver");
    Connection conn=DriverManager.getConnection("jdbc:oracle:thin:@192.168.0.13:1521:
    ora_sid","scott","tiger");
    String st="select * from emp";
    PreparedStatement ps=conn.prepareStatement(st);
    ResultSet rs=ps.executeQuery();
    while(rs.next())
    {
       String s1=rs.getString(1);
       String s2=rs.getString(2);
       String s3=rs.getString(3);
      System.out.println(s1+" "+s2+" "+s3);
    }
    conn.close();
    }
    }

    /*here 192.168.0.13 is the ip-address of the machine where oracle server is installed. If your system is a stand-alone one the instead of ip-address you can give "localhost" or loop-back address "127.0.0.1", and "1521" is the default port number of connecting oracle with java..*/
    0 0

    Utsav143 

    answered 3 years ago

      More

         
         

        Ask a Question via Twitter

        Send a question to @askblurtit and we will publish it online and send you a reply everytime you receive an answer.

        Blurtit Store

        Get T-shirts, hoodies, caps and more at the Blurtit store

        Blurtit International