为人尽量保持低调。尊重别人,不要随便去打断别人的发言,认真的听别人的言语。不要老是想着把话题抢过来抓在自己手里。不能放开的人是没法获得的。
|
首页
| |
发新文章
|
联系
|
聚合
|
管理
tomcat连接数据库(SQL2000)
新建工程testmydb;
在$tomcat\conf\Catalina\localhost下建立testmydb.xml
<?
xml version="1.0" encoding="UTF-8"
?>
<
Context
>
<
Resource
name
="jdbc/testmydb"
type
="javax.sql.DataSource"
password
="******"
driverClassName
="com.microsoft.jdbc.sqlserver.SQLServerDriver"
maxIdle
="2"
maxWait
="5000"
username
="babyuser"
url
="jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=bbs"
maxActive
="4"
/>
</
Context
>
在$tomcat\webapps\testmydb\WEB-INF\下新建web.xml
<?
xml version="1.0" encoding="ISO-8859-1"
?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<
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/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version
="2.4"
>
<
display-name
>
Tomcat Documentation
</
display-name
>
<
description
>
Tomcat Documentation.
</
description
>
<
resource-ref
>
<
description
>
sqlserverDB Connection
</
description
>
<
res-ref-name
>
jdbc/testmydb
</
res-ref-name
>
<
res-type
>
javax.sql.DataSource
</
res-type
>
<
res-auth
>
Container
</
res-auth
>
</
resource-ref
>
</
web-app
>
在$tomcat\webapps\quickstart\目录下新建index.jsp文件
<%
@ page contentType
=
"
text/html;charset=gb2312
"
%>
<%
@ page import
=
"
java.sql.*
"
%>
<%
@ page import
=
"
javax.naming.*
"
%>
<%
@ page import
=
"
javax.sql.*
"
%>
<%
!
public
static
String
getGBString(
String
src) {
try {
return
new
String
(src.getBytes(
"
ISO-8859-1
"
),
"
gb2312
"
);
} catch (java.io.UnsupportedEncodingException e) {
return
null
;
}
}
%>
<
html
><
head
><
title
>
JDBC Test
</
title
></
head
><
body
>
<%
Connection conn
=
null
;
Statement stmt
=
null
;
ResultSet rs
=
null
;
ResultSetMetaData md
=
null
;
try
{Context initCtx
=
new
InitialContext();
DataSource ds
=
(DataSource)initCtx.lookup(
"
java:comp/env/jdbc/quickstart
"
);
if
(ds!
=
null
)
{
out.println(
"
已经获得DataSource
"
);
//
out.println(ds.toString());
conn
=
ds.getConnection();
stmt
=
conn.createStatement();
out.println(
"
aa
"
);
rs
=
stmt.executeQuery(
"
SELECT TOP 5 * FROM Dv_Topic WHERE (Boardid = 37) AND (istop = 1)
"
);
md
=
rs.getMetaData();
out.println(
"
<table border=1>
"
);
out.println(
"
<tr>
"
);
for
(
int
i
=
0
;i
<
md.getColumnCount();i
++
)
{
out.println(
"
<td>
"
+
md.getColumnName(i
+
1
)
+
"
</td>
"
);
}
while
(rs.next())
{
out.println(
"
<tr>
"
);
out.println(
"
<td>
"
+
rs.getString(
1
)
+
"
</td>
"
);
out.println(
"
<td>
"
+
getGBString(rs.getString(
2
))
+
"
</td>
"
);
out.println(
"
<td>
"
+
rs.getString(
3
)
+
"
</td>
"
);
out.println(
"
<td>
"
+
rs.getString(
4
)
+
"
</td>
"
);
out.println(
"
</tr>
"
);
}
out.println(
"
</table>
"
);
conn.close();
}
}
catch(Exception e)
{
out.println(e.toString());
System.out.println(e.toString());
}
%>
</
body
></
html
>
点击
http://localhost:8080/testmydb/
链接成功!会出现
已经获得DataSource aa
TopicID
Title
Boardid
PollID
LockTopic
Child
PostUsername
PostUserid
DateAndTime
hits
Expression
VoteTotal
LastPost
LastPostTime
istop
isvote
isbest
PostTable
SmsUserList
IsSmsTopic
LastSmsTime
TopicMode
Mode
GetMoney
UseTools
GetMoneyType
HideName
201314
亲吻北京!——我们伟大的祖国!
37
0
当然tomcat连接需要sql2000的3个驱动文件msutil.jar、msbase.jar、mssqlserver.jar
sql2000需要升级到sp4;
发表于 2008-04-25 15:35
(北京)木木
阅读(386)
评论(0)
编辑
收藏
所属分类:
java
新用户注册
刷新评论列表
只有注册用户
登录
后才能发表评论。
网站导航:
博客园
IT新闻
知识库
C++博客
博问
相关文章:
Redis 数据库的键值设计
Redis示例配置文件 2.4
JVM监控工具介绍
Dbutils 详解
JAVA基础知识精华总结
jdk5的拆箱与装箱
jdk1.5 Arrays 学习笔记
[转]Struts2 如何在 jdk 1.4下运行
tomcat porgram with many error in linux but it's fine in windows
javascript+java截取图像,图像处理
随笔:8 文章:23 评论:45 引用:0
<
2024年11月
>
日
一
二
三
四
五
六
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
7
留言簿
(5)
给我留言
查看公开留言
查看私人留言
文章分类
(25)
html(2)
(rss)
java(15)
(rss)
javascript(7)
(rss)
正则表达式(1)
(rss)
最新随笔
1. Redis 数据库的键值设计
2. Redis示例配置文件 2.4
3. JVM监控工具介绍
4. 悟
5. 8种代码臭味
6. Java多线程编程总结
7. Dbutils 详解
8. 一套完整的javascript面试题--答案
9. 一套完整的javascript面试题--试题
10. JAVA基础知识精华总结
搜索
积分与排名
积分 - 38264
排名 - 1191
最新评论
1. re: Dbutils 详解
学习中
--江鸽
2. re: 原创【整合iis+tomcat(成功)】
为什么我没成功!运行很慢
--hailan
3. re: 原创【整合iis+tomcat(成功)】
通过你的表述。 结果有用了。 但是貌似读取文件好慢。还是多谢了!!!
--ff
4. re: 原创【整合iis+tomcat(成功)】
谢谢
--mens moncler coats
5. re: java 图片切割,缩放,转换类型
垃圾自己检查下
--飞速度放松