It always maintains a connection to the database.
Example:
import java.sql.*;
import javax.sql.*;
import javax.sql.rowset.*;
import com.sun.rowset.*; //classpath to rt.jar
import java.io.*;
public class demo {
public static void main(String[] args)throws Exception {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
JdbcRowSet jrs = new JdbcRowSetImpl();
jrs.setUrl("jdbc:odbc:dsn");
jrs.setUsername("system");
jrs.setPassword("oracle");
jrs.setCommand("Select *from emp");
jrs.execute();
ResultSetMetaData meta=jrs.getMetaData();
int colcount=meta.getColumnCount();
while(jrs.next()) {
for(int i=1;i<=colcount;i++) {
System.out.print(jrs.getString(i)+" : ");
}
System.out.println();
}}}
No comments:
Post a Comment