- 浏览: 112393 次
- 性别:
- 来自: 济南
文章分类
最新评论
-
yangbaodi516:
XMLInputFactory2 xmlif = (XMLIn ...
基于Woodstox的StAX 2 解析XML -
AK53pro:
SSL证书怎么伪造啊...有数字签名的啊...
SSL中间人攻击及防范 -
lysino:
若把此问题交给oracle的sequence来解决岂不是很简单 ...
一个循环流水号实现,求评 -
zuzong:
写的时候,考虑过用indexof查一次,删一次,后来写着写着就 ...
过滤掉非指定保留的html元素,保留元素间的内容和指定的html -
zuzong:
我一开始用的stringbuffer,发现删除了那些不需要的h ...
过滤掉非指定保留的html元素,保留元素间的内容和指定的html
这是我最早在csdn发的文章,2007年3月13日,很有纪念意义啊,真的精工细作,仔仔细细的写,认真的排版,虽然现在看着还是有些简陋,但在当时对我来说真是激动啊,第一次发技术文章~~~~
咱废话不多说,http://localhost:8080 , 开始...
这是全局配法:
1、TomCat Administration
|_
Resources
|_
Data sources
|_
Data Source Actions(右上角处)
|_
Create New Data Source(下拉菜单中选择此项)
2、在新建数据源中,设置Vaule
Property Value
JNDI Name: jdbc/mysql(名字随便)
Data Source URL: jdbc:mysql://localhost:3306/<databasename>
JDBC Driver Class: org.gjt.mm.mysql.Driver
User Name: root(根据自己设置MySql的用户名来定)
Password: ××××××
。
。
。
。
剩下的视应用的情况来定,一般默认就可。
3、配置XML
来到TomCat的安装目录 ./conf/server.xml
再到自己的WEB-INF/web.xml
OK!重启tomcat,写个TestJsp.jsp
咱废话不多说,http://localhost:8080 , 开始...
这是全局配法:
1、TomCat Administration
|_
Resources
|_
Data sources
|_
Data Source Actions(右上角处)
|_
Create New Data Source(下拉菜单中选择此项)
2、在新建数据源中,设置Vaule
Property Value
JNDI Name: jdbc/mysql(名字随便)
Data Source URL: jdbc:mysql://localhost:3306/<databasename>
JDBC Driver Class: org.gjt.mm.mysql.Driver
User Name: root(根据自己设置MySql的用户名来定)
Password: ××××××
。
。
。
。
剩下的视应用的情况来定,一般默认就可。
3、配置XML
来到TomCat的安装目录 ./conf/server.xml
<Context path="/DBTest" docBase="DBTest" debug="5" reloadable="true" crossContext="true"> <!-- maxActive: Maximum number of dB connections in pool. Make sure you configure your mysqld max_connections large enough to handle all of your db connections. Set to 0 for no limit. --> <!-- maxIdle: Maximum number of idle dB connections to retain in pool. Set to -1 for no limit. See also the DBCP documentation on this and the minEvictableIdleTimeMillis configuration parameter. --> <!-- maxWait: Maximum time to wait for a dB connection to become available in ms, in this example 10 seconds. An Exception is thrown if this timeout is exceeded. Set to -1 to wait indefinitely. --> <!-- username and password: MySQL dB username and password for dB connections --> <!-- driverClassName: Class name for the old mm.mysql JDBC driver is org.gjt.mm.mysql.Driver - we recommend using Connector/J though. Class name for the official MySQL Connector/J driver is com.mysql.jdbc.Driver. --> <!-- url: The JDBC connection url for connecting to your MySQL dB. The autoReconnect=true argument to the url makes sure that the mm.mysql JDBC Driver will automatically reconnect if mysqld closed the connection. mysqld by default closes idle connections after 8 hours. --> <Resource name="jdbc/TestDB(要与自己的JNDI一致)" auth="Container" type="javax.sql.DataSource" maxActive="100" maxIdle="30" maxWait="10000" username="javauser(与自己的一致)" password="javadude(与自己的一致)" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/javatest?autoReconnect=true(一致)"/></Context>
再到自己的WEB-INF/web.xml
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2eehttp://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4"> <description>MySQL Test App</description> <resource-ref> <description>DB Connection</description> <res-ref-name>jdbc/TestDB(注意)</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref></web-app>
OK!重启tomcat,写个TestJsp.jsp
<%@page contentType="text/html"%> <%@page pageEncoding="UTF-8"%> <%@ page import="java.sql.*"%> <%@ page import="javax.sql.*"%> <%@ page import="javax.naming.*"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>JSP Page</title> </head> <body> <h1>JSP Page</h1> <% out.println("开始>>>"); try{ InitialContext ct = new InitialContext(); DataSource ds = (DataSource)ct.lookup("java:comp/env/jdbc/mysql"); Connection conn = ds.getConnection(); Statement stm = conn.createStatement(); String sql = "select * from help_category"; ResultSet rs = stm.executeQuery(sql); while(rs.next()){ out.println("<br>"); for(int i=0;i<rs.getMetaData().getColumnCount();i++){ out.print(rs.getString(i+1)); } } out.print("经过'rs'循环"); }catch(Exception ex){ out.print("Error: "+ex.getMessage()); ex.printStackTrace(); } %> </body> </html>
发表评论
-
Java虚拟机(JVM)参数配置说明
2011-10-14 16:50 927转自 http://lavasoft.blog.51cto.c ... -
实现非阻塞套接字的一种简单方法 JSSE 和 NIO
2011-10-14 16:39 1374转自http://www.ibm.com/developerw ... -
基于事件的 NIO 多线程服务器
2011-10-14 16:24 1010转自 http://www.ibm.com/developer ... -
windows下批量删除svn文件夹
2011-06-10 16:02 1625Windows Registry Editor Versi ... -
Spring 3.x 全注解配置
2011-06-10 15:47 2084web.xml <listener> & ... -
Log4j配置文件XML方式和按包路径分开输出日志
2011-06-10 14:20 12509使用Log4j,则推荐用XML来配置属性参数,优点是打印输出更 ... -
基于Woodstox的StAX 2 解析XML
2011-06-08 17:56 9204StAX (Streaming API for XML)面向流 ... -
Spring 3.0.5 MVC 基于注解的拦截器
2011-05-23 17:28 3060org.springframework.web.servlet ... -
Spring 3.0.5 MVC 异常处理
2011-05-23 16:33 2357SimpleMappingExceptionResolver ... -
过滤掉非指定保留的html元素,保留元素间的内容和指定的html
2011-03-05 21:07 1429public static void main(Strin ... -
根据表单对象,为业务对象赋值
2010-09-08 15:22 1058package com.team.engine.util; ... -
在iBatis中加入c3p0数据库连接池
2009-06-13 16:32 4515我看论坛里有两个人写了在iBatis中加入c3p0,我也就不跟 ... -
enum的写法
2009-01-07 11:12 1353public static enum TTutorial ... -
Spring之IOC
2008-12-21 01:05 1095Spring的功能是 ... -
List的JavaExcel工具类(读,写)
2008-12-21 01:03 111507年9月的 读XML: import java.i ... -
List的JavaExcel工具类
2008-12-21 00:58 1467这也是大约在夏季,应该接近秋天了吧 支持office200 ... -
读,写 properties属性文件
2008-12-21 00:50 2105这个是07年,可能是在8月份写的。。。大约在夏季。。。 ... -
分~页~,自动生成表格
2008-12-21 00:36 1384这是07年11月发在csdn blog里的,隔得时间太长,都记 ... -
java正则式的应用,持续更新。。。
2008-12-20 23:55 1189String ss = "呵呵HAAhaha2 ... -
控制Word,Excel在浏览器中打开,还是下载
2008-12-20 23:41 4939<%@ page contentType=&quo ...
相关推荐
tomcat5.5.20.rar,tomcat
apache tomcat 5.5.20apache tomcat 5.5.20apache tomcat 5.5.20apache tomcat 5.5.20apache tomcat 5.5.20
tomcat5.5.20 带native libarary 放在windows/system32/下面就可以了
Tomcat5.5.20中文使用帮助文档
Tomcat 5.5.20 汉化版 for Windows jaxmao-tomcat-5.5.20
内含tomcat5.5.20和tomcat6.0.1
Tomcat5.5.20汉化版 安装简单方便...
apache-tomcat-5.5.20.rar
apache-tomcat-5.5.20;apache-tomcat-5.5.20-admin。这里面有两个软件,都是JAVA必不可少的,希望对大家有帮助。
免安装版下载tomcat,tomcat-5.5.20.zip,用了很久没什么问题。解压完后就可以使用
开发web应用程序发布时所用的tomcat服务器,tomcat猫!
TOMCAT_IIS_connect_by_flashlm Tomcat5.5.20 与 IIS5.1、IIS6.0的整合方法及心得
tomcat-5.5.20 的 admin 插件
tomcat for liunx
apache-tomcat-5.5.25.exe+连接池.rar+sqljdbc
apache-tomcat-5.5.20.exe
免安装版下载tomcat,tomcat-5.5.20.zip,自用的,在树莓派上搭建java服务很好用
all native library all native library
3.要想管理模块能够顺利运行,那么还要保证一点:确保设置了CATALINA_HOME这个系统环境变量,变量的值为你的tomcat的安装目录。如果你不愿意设置环境变量,那么也有一个方法,就是将【tomcat的安装目录】\server\...