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
 

"MM.MySQL and the MySQL Database System"
Vol. 5, Issue 12, p. 76

	


Listing 1



	
	// Assume conn is a java.sql.Connection to a MySQL database 
	// that has already been created using DriverManager.getCon-
	// nection()

	Statement stmt = conn.createStatement();

	stmt.executeUpdate("INSERT INTO myTable VALUES ('abc', '123')");

		// Get the value for the AUTO_INCREMENT primary key

	long autoKey = ((org.gjt.mm.mysql.Statement)stmt).getLastIn-			sertID();

	// Get the (potentially) large update count (in this case 			// should be "1"

	long bigUpdateCount = ((org.gjt.mm.mysql.Statement)stmt).get   	LongUpdateCount();
	
Listing 2	


	// Assume conn is a java.sql.Connection to a MySQL database 
	// that has already been created using DriverManager.getCon-
	// nection(), and that we have a java.security.cert.Certifi-
	// cate named "cert" given to us by some client that we want 	// to store in the "serObject" table in our MySQL database
	
	PreparedStatement pstmt = 
	conn.prepareStatement("INSERT INTO serObject values (?, ?)");

pstmt.setString(1, "username");
pstmt.setObject(2, cert);

// By calling executeUpdate here, a row will be inserted, 
// where the user column will be set to "username" and the 
// cert column will have a serialized version of
// the certificate

pstmt.executeUpdate();

pstmt.close();

// Okay, now let's retrieve the certificate

Statement stmt = conn.createStatement();

ResultSet rs =  stmt.executeQuery("select cert from serObject where user='username'");

while (rs.next()) {
// If you're using MM.MySQL 2.0.2 or earlier, retrieve the 
// certificate using the utility class
	
java.security.cert.Certificate aSerializedCert = 
	(java.security.cert.Certificate)org.gjt.mm.mysql.Util.readOb-			ject(rs, 1);

// Or, if you're using MM.MySQL 2.0.3 or newer, use this 
// format:

java.security.cert.Certifcate aSerializedCert = 
(java.security.cert.Certificate)rs.readObject(1);

// Now, do something with the certificate

}

rs.close();

stmt.close();

  
 
 

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.