Monday, January 13, 2014

Java JDBC programming Example 6

/Note: create  a DSN in the name of sql that is pointing the table name limbs in the database with three String column  names things,legs,arms



//rs is not scrollable RETRIVEING COLUMN VALUES using column names
import java.sql.*;
class Jdbc6{
public static void main(String...arg) throws Exception{
         Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
         Connection c =  DriverManager.getConnection("jdbc:odbc:sql");
         Statement  st = c.createStatement();
         ResultSet r = st.executeQuery("select * from limbs");
        try{

while(r.next()){
     
              System.out.println(r.getString("things"));
              System.out.println(r.getInt("legs"));
              System.out.println(r.getInt("arms"));
 
        }
       
         }catch(Exception e){System.out.println("Error :");e.printStackTrace();}
      r.close();
      st.close();
      c.close();
}
}

Post a Comment