Tomcat下Teradata的JNDI数据源配置

这里以tomcat-5.5.7为例,tomcat 6配置与这不一样。

1,先在tomcat-5.5.7\conf\server.xml的<Host></Host>中增加如下代码:

<Context crossContext="true" debug="5" docBase="F:\JAVA\FxycWorkSpace\groupkpi\WebRoot"

                    path="/groupkpi" reloadable="true">

        <Resource name="jdbc/TeradataDSCIM"

                type="javax.sql.DataSource" auth="Container"

                driverClassName="com.ncr.teradata.TeraDriver" maxActive="100"

                maxIdle="30" maxWait="10000" url="jdbc:teradata://数据库IP/TMODE=TERA,CHARSET=ASCII,CLIENT_CHARSET=cp936,DATABASE=sxedrm2"

                username="数据库用户名" password="密码" />

</Context>

2.把数据库驱动包拷贝到\tomcat-5.5.7\common\lib目录下。

3.重启Tomcat,并用下面的文件进行测试。

<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%@ page language="java"%>
<%@ page import="java.sql.*" %>  
<%@ page import="javax.sql.*" %>  
<%@ page import="javax.naming.*" %>
<%@page import="com.teradata.db.DBQueryEngine"%>
<%
String jndi_name="java:comp/env/jdbc/TeradataDSCIM";
Context ctx = new InitialContext();  
if(ctx == null )  
	throw new Exception("No Context");  
DataSource ds = (DataSource)ctx.lookup(jndi_name);
Connection conn = ds.getConnection();
DBQueryEngine dLocal = new DBQueryEngine();
dLocal.createConnection(jndi_name);

String Sql = "SEL DIM_VALUE_ID FROM TAP_C_GRP_DIM_VALUE WHERE PAR_DIM_VALUE_ID = '01' and STATISTICS_TYPE_ID = 1";
        try{
	dLocal.executeQuery(Sql);
	while(dLocal.next()){
		System.out.println(dLocal.getString(1));
	}			
        }catch(Exception e){						
        }
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    
    <title>My JSP 'index.jsp' starting page</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
  </head>
  
  <body>
    This is my JSP page. <br>
  </body>
</html>

 相关jar如附件。

你可能感兴趣的:(java,sql,tomcat,jdbc,SQL Server)