Results 1 to 3 of 3

Thread: JDBC in Java

  1. #1
    Junior Member
    Join Date
    Aug 2007
    Answers
    2

    Question JDBC in Java

    What is the process to make connectivity with database in Java?
    Give me the full syntax of database connectivity?


  2. #2
    Contributing Member
    Join Date
    Sep 2006
    Answers
    962

    Re: JDBC in Java

    Properties props = new Properties();
    props.setProperty("user", "contacts");
    props.setProperty("password", "blackbook");
    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/contacts/", props);


    Statement stmt = con.createStatement();
    String query = ... // define query
    stmt.executeQuery(query);

    MORE INFORMATION....

    --------------------------
    suresh


  3. #3
    Junior Member
    Join Date
    Oct 2007
    Answers
    1

    Re: JDBC in Java

    Quote Originally Posted by santhisudha View Post
    What is the process to make connectivity with database in Java?
    Give me the full syntax of database connectivity?
    import java.sql.*;
    class Test
    {
    public static void main(String args[]) throws SQLException
    {
    String s;
    try
    {
    Class.forName("oracle.jdbc.driver.OracleDriver");
    Connection cn=DriverManager.getConnection("jdbcracle:thin:@localhost:1521rcl","scott","t");
    Statement st=cn.createStatement();
    ResultSet rs=st.executeQuery("select * from dept");
    while(rs.next())
    {
    System.out.println(rs.getString(1));
    }
    st.close();
    cn.close();
    }
    catch(Exception ex)
    {
    System.out.println("The exception raised is : " + ex);
    }

    }
    }

    you need to set classpath and path

    for that refer http://www.planet-source-code.com/vb...=5551&lngWId=2


    Last edited by admin; 10-03-2007 at 06:42 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact