Database connection

J-ASP provides an ADO (ActiveX Data Object) interface that allows you to access database through JDBC Driver. Use the following syntax to set the ConnectionString.


1. If you use the JDBC driver:

Driver=drivername;URL={JDBC url};UserID=userid;Password=password;

URL - a database url of the form jdbc:subprotocol:subname
UserID - the database user on whose behalf the connection is being made
Password - the user's password

For example: If you use Oracle JDBC driver, you can change your asp connection string as following codes:

<%
Dim DBConn
Dim strCnxn
strCnxn = "Driver=oracle.jdbc.driver.OracleDriver;" &_
"URL = {jdbc:oracle:thin:@OracleSvr:ORCL};" &_
"UserID = SCOTT;Password=TIGER;"
Set DBConn = Server.CreateObject("ADODB.Connection")
DBConn.Open strCnxn
%>


2. Set Connection properties to connect database

For example:

<%
Dim DBConn
Set DBConn = Server.CreateObject("ADODB.Connection")
Conn.Provider = "org.gjt.mm.mysql.Driver"
Conn.UserName = "root"
Conn.Password = "secret"
Conn.ConnectURL = "jdbc:mysql://mySQLSvr:3306/test"
Conn.Open
%>


3. Using JDBC-ODBC bridge

Using JDBC-ODBC bridge driver to access database:

DSN=Data Source Name;UID=userid;PWD=password


4. Using JNDI Data Source

If you have created the JNDI name in your webserver, J-ASP can call the Data Source directly. You may change the connection string to the following format:

"DSN=JNDI-NAME;UID=UserName;PWD=Password"

For more information, please see Connection Pooling.

<%
Dim DBConn
Dim strCnxn
strCnxn = "DSN=jdbc/ORCLTest;UID=SCOTT;PWD=tiger"
Set DBConn = Server.CreateObject("ADODB.Connection")
DBConn.Open strCnxn
%>

Note: You must set the JDBC driver to the CLASSPATH. J-ASP ADO only supports the JDBC2.0 or later. If you are using the JDBC1.x driver, J-ASP ADO will be not functional.