import java.io.*; Mr.D.Ramanjaneyulu
you can reach me at d_ramu2002@yahoo.com program-2
import java.sql.*;
public class ramuexce
{
public
static void main(String s[]) throws
Exception
{
try
{
//general method-1
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection
con=DriverManager.getConnection("Jdbc:Odbc:oradsn","ramu","ram");
//method-2
Statement
st=con.createStatement();
ResultSet
rs=st.executeQuery("select * from student");
/*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
while(rs.next())
{
System.out.println(rs.getInt(1));// if we put beyond the existing column we will get an error which will
totally stop the program even no partial execuation
System.out.println(rs.getString(2));
System.out.println(rs.getInt(3));//
here i am mentaioning INT datatype insted of Float datatype now you will get
the warning which allows you partial execuation
System.out.print("\n");
}
//implementing the SQLEXCEPTION class for knowing the EXCEPTION for
knowing details
//implementing SQLWARNING CLASS for knowing SQLWARNINGS AT COMPILETIME
SQLWarning w= rs.getWarnings();
System.out.println("now you are
in warnings blockTHE FIRST WARNING IS ");
System.out.println("THE MESSAGE
IS"+w.getMessage());
System.out.println("THE STATE IS
"+w.getSQLState());
System.out.println("THE ERROR
NUMBER IS "+w.getErrorCode());
w.getNextWarning();
System.out.println("THE NEXT
WARNING IS ");
System.out.println("THE MESSAGE
IS"+w.getMessage());
System.out.println("THE STATE IS
"+w.getSQLState());
System.out.println("THE ERROR
NUMBER IS "+w.getErrorCode());
rs.close();
st.close();
con.close();
}//end of try
catch(SQLException e)
{
System.out.println("THE EXCPTIONS ARE "+e.getMessage());
}// end of exception
}// end of main method
}//end of main class
కామెంట్లు లేవు:
కామెంట్ను పోస్ట్ చేయండి