FEEDBACK
Browse Groups Java  »  Java Database Connectivity
Name

Email

Nidhika
Posted on 09 Jan 08, 2:22 AM

Steps required to implement a Java Database Program

STEP 1: Loading Drivers
Class.ForName("sun.jdbc.odbc.JdbcOdbcDriver")

STEP 2: Making the Connection
Connection conn = DriverManager.getConnection("jdbc:odbc:");

STEP 3: Creating JDBC Statements
Statement stmt = conn.createStatement();

STEP 4: Executing the Statement
ResultSet rs = stmt.executeQuery("select * from student");

STEP 5: Looping through the ResultSet
System.out.println(rs.getInt("ID"));

STEP 6: Closing the Connection and Statement Objects
conn.close()
stmt.close()

Thanks & Regards
Nidhika

Raameshwar
Posted on 28 Jan 08, 7:24 AM

Hi,

A most important step is missed in this.  Do you know what is that ? :-)

Cheers,
Raameshwar.

Last edited by raameshwar (2008-01-28 07:25:27)

Nidhika
Posted on 29 Jan 08, 3:54 AM

Hi Raameshwar,

I think Step 6 could be like this:

STEP 6: Closing the Connection and Statement Objects
rs .close()
stmt.close()
conn.close()

If still I am missing something,please let me know.

Cheers
Nidhika

Raameshwar
Posted on 29 Jan 08, 11:02 PM

Hi Nidhika,

It is a method in ResultSet but not close() ( close() is also important. but here i am talking about a step without which this code will not work ). Try again once. If you couldn't find, i will give the answer next time :-)
OK i will give you a clue, It should come before STEP 5: Looping through the ResultSet step.

Happy Debugging,
Raameshwar.

Last edited by raameshwar (2008-01-29 23:20:35)

Nidhika
Posted on 30 Jan 08, 4:59 PM

Hi Raameshwar

I think this step I was missing   

    // Display the SQL Results
     while(rs.next(  )) {
       System.out.println(rs.getString("FIRST_NAME"));
     }


Thanks
Nidhika

Raameshwar
Posted on 30 Jan 08, 9:23 PM

Yes  next() is the method i was talking about.  This method takes the cursor to the first result.  Traditionally people use this method inside a while() and thus think its just a condition for looping.  But truly it is an important step which helps us in traversing the RS.

BR,
Raameshwar.

Last edited by raameshwar (2008-01-30 21:24:25)

Add New Reply