tomcat6.0 + JSP + mysqlÊý¾Ý¿âÁ¬½Ó³ØÅäÖÃ
tomcat6.0 + JSP + mysqlÊý¾Ý¿âÁ¬½Ó³ØÅäÖÃ
»·¾³£ºtomcat6.0 £¬mySQL 5.021
°ÑmysqlÇý¶¯°ü·Ö±ð·Åµ½%TOMCAT_HOME%/lib ºÍÄãµÄÓ¦ÓõÄWEB-INF\libÎļþ¼ÐÏÂÃæ
1¡¢ÐÞ¸Ä%TOMCAT_HOME%/conf/server.xml,Ìí¼ÓÈçÏÂÄÚÈÝ£¨²¿·Ö²ÎÊýÇë±¾µØ»¯£©£º
<Context path="/web" docBase="web" debug="0" reloadable="true" crossContext="true">
<Resource name="jdbc/query" auth="Container"
type="javax.sql.DataSource" driverClassName="org.gjt.mm.mysql.Driver"
maxIdle="20" maxWait="5000" username="username" password="password"
url="jdbc:mysql://localhost:3306/DataBaseName" maxActive="100"
removeAbandoned="true" removeAbandonedTimeout="60"
logAbandoned="true"/>
</Context>
2¡¢Ð޸ĶÔÓ¦Ó¦ÓõÄweb.xml£¬ÔÚ</web-app>Ç°Ìí¼ÓÈçÏÂÄÚÈÝ£º
<ResourceLink name="jdbc/query" global="jdbc/query" type="javax.sql.DataSourcer"/>
ÖØÆôtomcat£¬´ó¹¦¸ã³É£¡
Ó¦ÓÃʵÀýÈçÏ£º
<%@ page contentType="text/html; charset=gb2312" %>
<%@ page import="javax.naming.Context" %>
<%@ page import="javax.sql.DataSource"%>
<%@ page import="javax.naming.InitialContext"%>
<%@ page import="java.sql.*"%>
<html>
<body>
123
<%
DataSource ds = null;
try{
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
//´ÓContextÖÐlookupÊý¾ÝÔ´¡£
ds = (DataSource)envCtx.lookup("jdbc/query");
Ïà¹ØÎĵµ£º
½ñÌìÅöµ½ÕâÑùµÄÒ»¸öÎÊÌ⣺
ÎÒµçÄÔÉÏ°²×°ÁËwampserver£¬È»ºó´ò¿ªphpMyAdmin½øÐÐÊý¾Ý¿â¹ÜÀí²Ù×÷ʱ£¨´´½¨Êý¾Ý¿â£©£¬´´½¨ÍêÖ®ºó£¬µ½wampserver°²×°Ä¿Â¼µÄmysqlĿ¼Ï²鿴¸Õ´´½¨µÄÊý¾Ý¿â¡£¡£¡£ÔõôÕÒҲûÕÒµ½£¬ÎÒ¾ÍÓôÃÆ£¬È»ºó¾ÍÈ¥²éÕÒÎÊÌâµÄÔÒò£¬½á¹ûÊÇÕ⣺ÒòΪÎÒµçÄÔÉÏ°²×°WampServer֮ǰÓа²×°¹ýMysql£¬ËùÒÔÖ®ºó¶Ô ......
×î½üÊÕµ½Ò»¸öÏîÄ¿µÄÔ´´úÂ룬²¿ÊðÒÔºó´ò¿ªÒ³Ãæ·¢ÏÖJSPÒ³ÃæÖеÄEL±í´ïʽ¶¼Ã»ÓнâÎö£¬¶¼ÊÇÔÑùÏÔʾ¡£
ÉÏÍøËÑË÷ÁËÒ»ÏÂÔÒò£¬ÔÀ´ÊÇServlet°æ±¾µÄÎÊÌâ¡£ÔÀ´ServletÖпÉÒÔÉ趨ÊÇ·ñ½âÎöEL±í´ïʽ£¬Ö»ÓÐ2.4°æ±¾µÄServletĬÈÏÊǽâÎöEL±í´ïʽµÄ£¬¶øÆäËû°æ±¾ÊÇĬÈϲ»½âÎöEL±í´ïʽ£¬²éÁËһϳÌÐò£ ......
select
count(*) as mcount ,
left(create_time,10) as ptime ,
count(if(receive_msg is null,id,null)) as nullcount ,
count(if(receive_msg = '1',receive_msg,null)) as apfcount ,
count(if(receive_msg = '2',receive_msg,null)) as dttcount ,
count(if(receive_msg = '3',receive_ms ......
ÔÚJSPÖÐÒýÓÃjsÎļþ»á·¢ÉúÒýÓò»µ½µÄÎÊÌ⣺
ÔÚwebÏîÄ¿À´æÔÚWEB-INFÎļþĿ¼£¬ÎҵĴíÎó×ö·¨ÊÇ°Ñjs£¬image£¬CSS¶¼·ÅÔÚ´ËÎļþ¼ÐÏ¡£×î³õÒÔΪÊÇÏà¶Ô·¾¶Óë¾ø¶Ô·¾¶¸ã´íÁË£¬µ«ÊÇÔõôÐÞ¸ÄÒ²ÎÞ·¨½â¾öÎÊÌâ¡£µ÷ÓÃjsʱ×ÜÊǻᱨȱÉÙ¶ÔÏó£¬×îºóÁ˽âÊÇÒòΪWEB-INFÕâÀïµÄ¶«Î÷ÊDz»ÈÃÖ±½Ó·ÃÎʵġ£ËùÒԸı䷽·¨°ÑÕâЩΠ......