<?xml version="1.0" encoding="UTF-8" ?>

<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
    <title>Posteet: Blob</title> 
    <link>http://www.posteet.com/</link> 
    <description>Recent posteets posted to Posteet</description>
    <ttl>60</ttl>

    
    <item>
        <title>Saving a Serialized class into a MySQL Database.</title>
        <link>http://www.posteet.com/view/703</link>
        <description>
        <![CDATA[<pre>/**
	  * Actualitza l'objecte serialitzat (scorm_structure) de 
	  * l'usuari amb l'identificador indicat.
	  * 
	  * Nota! Fa un update, per tant ha d'existir l'usuari!
	  * 
	  * @param courseStudentName : El nom de la taula en que ho guardem.
	  * @param studentId : L'identificador de l'usuari.(int Type) 
	  * @param object : Retornarà l'UserObjective, caldrà fer un cast.
	  * @return int Type: Retornarà l'identificador del resultset.
	  * @throws Exception : Llança una excepció si hi ha un error.
	  */
	private int writeJavaObject(
			final String courseStudentName,
			final int studentId,
			final Object object) 
	 throws Exception {		
		String sqlUpdateScormStructure =
			&quot;UPDATE &quot; + courseStudentName
			+ &quot; set scorm_structure = ? WHERE student_id = ?&quot;;
                /** We already have
                  * private Connection conn = DriverManager.getConnection(url, userName, password);
                  */
		PreparedStatement pstmt =
			conn.prepareStatement(sqlUpdateScormStructure);
		
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		ObjectOutputStream oout = new ObjectOutputStream(baos);
		oout.writeObject(object); //serializing
		    
		// set input parameters
		pstmt.setBytes(1, baos.toByteArray());		    
		pstmt.setInt(2, studentId);
		pstmt.executeUpdate();

		// get the generated key for the id
		ResultSet rs = pstmt.getGeneratedKeys();
		int id = -1;
		if (rs.next()) {
			id = rs.getInt(1);
		}
		
		rs.close();
		pstmt.close();
		return id;
	}</pre> <a href="http://www.posteet.com/tags/Blob">[Blob]</a>  <a href="http://www.posteet.com/tags/Java">[Java]</a>  <a href="http://www.posteet.com/tags/MySQL">[MySQL]</a> ]]>        </description>
        <dc:creator>haduart</dc:creator>
        <pubDate>Tue, 29 Jan 2008 13:35:10 +0000</pubDate>

            <category>Blob</category>
            <category>Java</category>
            <category>MySQL</category>
    
    </item>


</channel>
</rss>
