Monday, 20 June 2016

JDBC PROGRAM TO WORK WITH CachedRowSet

JDBC PROGRAM TO WORK WITH  CachedRowSet

import com.sun.rowset.*;

import java.io.*;

class ChacheRowSetImpl

{

public static void main(String[] args) throws Exception
{
Class.forName("com.mysql.jdbc.Driver");

CachedRowSetImpl cr=new CachedRowSetImpl();

cr.setUsername("root");
cr.setPassword("root");
cr.setUrl("jdbc:mysql://localhost:3306/voidmain");

cr.setCommand("select * from account");

cr.execute();

FileOutputStream fos=new FileOutputStream("D:\\cached.txt");

ObjectOutputStream os=new ObjectOutputStream(fos);

os.writeObject(cr);

}
}

=======================================================================

import java.io.*;
import com.sun.rowset.*;

class ReadChache
{
public static void main(String[] args) throws Exception
{
FileInputStream fis=new FileInputStream("D:\\cached.txt");

ObjectInputStream ois=new ObjectInputStream(fis);

CachedRowSetImpl cr=(CachedRowSetImpl)ois.readObject();

while(cr.next())
{
System.out.println(cr.getInt(1)+"\t"+cr.getString(2)+cr.getString(3));
}
}
}

No comments:

Post a comment