Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents

...

This chapter describes how to integrate ALTIBASE and TOMCAT.

...

driverClassName

Altibase JDBC driver class Name

url

The connection string information for connecting with ALTIBASe. Enters jdbc:Altibase://IP:port_no/db_name"

 

Username

The database account

 

Password

The database password

maxActive

The maximum number of connections, 0 is unlimited. The default is 8.

 

initialSize

The initial size of connections. The default is 0.

 

maxIdle

The maximum number of connections that wait in the pool. The default is 8.

 

minIdle

The minimum number of connections that wait in the pool. The default is 0.

 

maxWait

The maximum connection attempt time (unit: millisec) -1 waits indefinitely. The default: infinite waiting.

validationQuery

The SQL statement used to check the validation of connecitonconnection

Must be specified as a select statement that returns at least one row

Ex) select 1 from dual

defaultAutoCommit

Sets autocommit mode. The default: true.

defaultTransactionIsolation

Sets Transaction Isolation level.

The values of REPEATABLE_READ, SERIALIZABLE, and the default can be set, and the default follows the default value of the DB server.

The isolation level of ALTIBASE is READ COMMITED by default.

removeAbandoned

Determines the removal function for the abandoned connection. The default is false.

When the connection is removed, the number of connections exceeds the value set for maxActive and is requested for connection.

The connection can be assigned when maxActive is not reached, abandoned connection removal does not occur.

 

removeAbandonedTimeout

Sets the time for removal of abandoned timeout. The default is 300.

 

logAbandoned

Determines whether to abandon stack information in the log when removing abandoned connections. The default is false.

...

In this case, java:/comp/env is a prefix used when looking up JNDI.

Code Block
languagejava
Context envContext  = (Context)new InitialContext().lookup("java:/comp/env");
DataSource ds = (DataSource)envContext.lookup("jdbc/Altibase");
Connection conn = ds.getConnection();

Or

Code Block
languagejava
Context initCtx = new InitialContext();                                    
DataSource ds =  (DataSource)initCtx.lookup("java:comp/env/jdbc/Altibase");
Connection conn = ds.getConnection();

The following is a jsp example program that integrate integrates with ALTIBASE using the JNDI Datasource set above.

Code Block
languagejava
<%@ page import="java.sql.*, javax.naming.*, javax.sql.*"%>
<%
Context initCtx = new InitialContext();
DataSource ds =  (DataSource)initCtx.lookup("java:comp/env/jdbc/Altibase");
Connection conn = ds.getConnection();
Statement stmt = conn.createStatement();
String query = "select to_char(sysdate,'yyyy/mm/dd hh24:mi:ss') from dual";
ResultSet rs = stmt.executeQuery(query);
if(rs.next()) {
     out.println(rs.getString(1));
}
rs.close();
stmt.close();
conn.close();
%>

...

The following is a jsp example program that integrates with ALTIBASe using the general JDBC method.

Code Block
languagejava
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.util.Properties"%>
<%
Class.forName("Altibase.jdbc.driver.AltibaseDriver");
Properties prop = new Properties();
prop.put("user", "sys");
prop.put("password", "manager");
String url = "jdbc:Altibase://192.168.56.110:20300/mydb";
String sql = "SELECT TO_CHAR(SYSDATE,'YYYY-MM-DD HH24:MI:SS') FROM DUAL";
 
Connection conn = null;
Statement stmt= null;
ResultSet rs = null;
try {
conn = DriverManager.getConnection(url, prop);
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while(rs.next()) {
        out.println(rs.getString(1));
}
}catch(Exception se) {
out.println(se.getMessage());
} finally {
    rs.close();
    stmt.close();
    conn.close();
}
%>