Database Reference
In-Depth Information
</body>
</html>
Telling Tomcat to save session records in MySQL
The default Tomcat default session storage mechanism uses temporary files. To save
sessions using JDBC with MySQL instead, follow this procedure:
1. Create a table to hold session records.
2. Make sure that Tomcat can access the proper JDBC driver.
3. Modify the appropriate Tomcat configuration file to specify use of a persistent ses‐
sion manager for the relevant application context.
None of these steps involve modifying the sample session script in any way, which
reflects how Tomcat implements session support above the application level.
1. Create the Tomcat session table.
Tomcat stores several types of information in the session table:
• The session ID. By default, IDs are 32-character MD5 values.
• The application name.
• The session data. This is a serialized string.
• Whether the session is valid, as a single byte.
• The maximum permitted inactivity time, as a 32-bit integer measured in seconds.
• The last access time, as a 64-bit integer.
The following table satisfies those specifications; create it now before proceeding:
CREATE TABLE tomcat_session
(
id VARCHAR ( 32 ) NOT NULL ,
app VARCHAR ( 255 ),
data LONGBLOB ,
valid_session CHAR ( 1 ) NOT NULL ,
max_inactive INT NOT NULL ,
update_time BIGINT NOT NULL ,
PRIMARY KEY ( id ),
INDEX ( app )
);
2. Place the JDBC driver where Tomcat can find it.
Because Tomcat itself manages sessions, it must be able to access the JDBC driver
used to store sessions in a database. It's common to install drivers in the lib directory
of the Tomcat tree so that they're available both to Tomcat and to applications. Install
Search WWH ::




Custom Search