HomeDigital EditionSys-Con RadioSearch Java Cd
Advanced Java AWT Book Reviews/Excerpts Client Server Corba Editorials Embedded Java Enterprise Java IDE's Industry Watch Integration Interviews Java Applet Java & Databases Java & Web Services Java Fundamentals Java Native Interface Java Servlets Java Beans J2ME Libraries .NET Object Orientation Observations/IMHO Product Reviews Scalability & Performance Security Server Side Source Code Straight Talking Swing Threads Using Java with others Wireless XML
 

"Serialized Database Connectivity"
Vol. 2, Issue 3, p. 54

	

Listing 1.

import java.io.*;
import java.sql.*;
import java.awt.*;

public class AppFrame extends Frame {

	public AppFrame () {
		super();

	this.setLayout(new FlowLayout(FlowLayout.CENTER));
		this.add(new Button("Close"));

		try {
	Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
              Connection c = DriverManager.getConnection("jdbc:odbc:JDBC", "dba", "sql");
	FileOutputStream ostream = new FileOutputStream("temp.dat");
	ObjectOutputStream out = new ObjectOutputStream(ostream);
	out.writeObject(this);
	ostream.close();
	String sql = "insert into tObject values ('Frame1', ?)";
	PreparedStatement prepare = c.prepareStatement(sql);
	FileInputStream istream = new FileInputStream("temp.dat");
	int count = istream.available();
	prepare.setBinaryStream(1, istream, count);
	prepare.executeUpdate();
	istream.close();
	prepare.close();
	c.close();
}
catch (Exception e) {}
}

public static void main (String args[]) {
	AppFrame app = new AppFrame();
	app.setSize(200,200);
	app.show();
}
}

 Listing 2		
	
import java.io.*;
import java.sql.*;
import java.awt.*;

public class GetFrame {

	public GetFrame () {}

	public static void main (String args[]) {
		try {
			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
		              Connection c = DriverManager.getConnection("jdbc:odbc:JDBC", "dba", "sql");
	String sql = "select Object from tObject where ObjName = 'Frame1' ";
	Statement s = c.createStatement();
	ResultSet r = s.executeQuery(sql);
	r.next();
			byte b[] = r.getBytes(1);
	FileOutputStream ostream = new FileOutputStream("temp,dat");
	ostream.write(b);
	ostream.close();
	FileInputStream istream = new FileInputStream("temp.dat");
	ObjectInputStream in = new ObjectInputStream(istream);
			Frame f = (Frame)in.readObject();
			f.setSize(200,200);
	f.show();
}
catch (Exception e) {}
}
}


 

All Rights Reserved
Copyright ©  2004 SYS-CON Media, Inc.
  E-mail: [email protected]

Java and Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. SYS-CON Publications, Inc. is independent of Sun Microsystems, Inc.