Archives: May 2009

Make Tomcat 5 to handle wmv (Windows Media Video) files

0

May 14, 2009 at 4:42 pm Filed in:App servers

This week I have uploaded two videos to the website of the institute I work for.  There was a problem with Tomcat related to wmv files because it was not recognizing the mime type and users where experiencing problems when trying to download the videos.

I was surfing internet looking for the solution to that problem and I found it:

All what it has to be done is to add a new mime type to the web.xml file  (the one inside of  Tomcat’s conf directory):


<mime-mapping>
    <extension>wmv</extension>
    <mime-type>application/octet-stream</mime-type>
</mime-mapping>

It could sound strange but this mime is not correct but that makes it to work for both IE and other browsers.

So edit the file and restart Tomcat, that is all.

Taken from:  Visit site

Clobs in Oracle 10g

0

May 4, 2009 at 1:16 pm Filed in:Oracle

CLOB is the Oracle’s data type used for storing large textual data objects.

There is a problem when using standar APIs for processing CLOB data, it is that PreparedStatement.setString() only allows to process strings up to 32765 byte. To solve it, Oracle 10g has introduced a new property called SetBigStringTryClob that allows developers to use the standar JDBC PreparedStatement.setString() and ResultSet.getString() functions for also processing CLOB data.

Next snippet shows how to achieve CLOB handling by setting new property when creating the connection:

import java.sql.Connection;
import java.sql.DriverManager;
import oracle.jdbc.OracleDriver;
import java.util.Properties;
..........

// Load the database details into the variables.
String url      = "jdbc:oracle:thin:@localhost:1521:orcl";
String user     = "scott";
String password = "tiger";

// Create the properties object that holds all database details
Properties props = new Properties();
props.put("user", user );
props.put("password", password);
props.put("SetBigStringTryClob", "true");

// Load the Oracle JDBC driver class.
DriverManager.registerDriver(new OracleDriver());

// Get the database connection
Connection conn = DriverManager.getConnection( this.url, this.props );

This new property forces the preparedStatement.setString() to use another newly introduced method, OraclePreparedStatement.setStringForClob(), which can be used alone instead of the standar APIs.  See how:

 import java.sql.*;
import java.io.*;
import java.util.*;
import oracle.jdbc.*;
import oracle.jdbc.pool.*;
..........

// Create SQL query to insert CLOB data and other columns in the database.
String sql = "INSERT INTO clob_tab VALUES(?)";

// Read a big file(larger than 32765 bytes).
// Note: method readFile() not listed here.
// It can be any method that reads a file.
String str = this.readFile("bigFile.txt");

// Create the OraclePreparedStatement object
opstmt = (OraclePreparedStatement)conn.prepareStatement(sql);

// Use the new method to insert the CLOB data (for data greater or lesser than 32 KB)
opstmt.setStringForClob(1,str);

// Execute the OraclePreparedStatement
opstmt.executeUpdate();
...........

Taken from:  Handling Clobs in Oracle 10g