3, ఏప్రిల్ 2012, మంగళవారం

THIS IS THE CODE SNIPPET WHICH EXPLAINS HOW TO CONNECT MS-ACCESS DATABASE BY USING THE JEE JDBC CONCEPT


import java.io.*;
import java.sql.*;
class ramu
{
                public static void main(String s[])  throws Exception
                {
                                   //general method-1
                                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                                Connection con=DriverManager.getConnection("Jdbc:Odbc:ravi");
                                  //method-2

                                  Statement st=con.createStatement();
                                ResultSet rs=st.executeQuery("select * from ram");
                                while(rs.next())
                                {
/*for(int i=1;i<=3;i++) //the index must start from the 1 only generally people are facing trouble by putting the value for index '0'
                                                {
                                                                Object o=rs.getObject(i);
                                                                System.out.println("result:"+o);

                                                }*/




// 2nd method this is the polished way of writing CODE to retrive  the data from the database
System.out.println(rs.getInt(1));
System.out.println(rs.getString(2));
System.out.println(rs.getInt(3));
System.out.print("\n");
                                }
}// end of main()
} // end of class


కామెంట్‌లు లేవు:

కామెంట్‌ను పోస్ట్ చేయండి