//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
import java.sql.*;
class Jdbc15{
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");
ResultSetMetaData rsmd = r.getMetaData();
int noofcol=rsmd.getColumnCount();
try{
while(r.next()){
for(int i =1;i<=noofcol-1;i++){
System.out.print(r.getString(i)+" ");
}
System.out.println();
}
}catch(Exception e){System.out.println("Error :");e.printStackTrace();}
r.close();
st.close();
c.close();
}
}
No comments:
Post a Comment