tomcat下配置jdbc连sqlserver数据源

news/2024/5/18 21:49:15 标签: Tomcat, JDBC, SQL Server, SQL, Web
1、将jtds-1.1.jar拷贝到tomcat安装目录下的common/lib目录下;
2、在tomcat的config目录下,在server.xml的<Host></Host>中加入以下代码
<Context path="/edorm">
<Resource
name="jdbc/edorm"
type="javax.sql.DataSource"
password="edorm"
auth="Container"
driverClassName="net.sourceforge.jtds.jdbc.Driver"
maxIdle="2"
maxWait="5000"
username="sa"
url="jdbc:jtds:sqlserver://192.168.0.88:1433/edorm_kf"
maxActive="4"/>
</Context>

注意path="/edorm"要根据你自己的项目名称来定
3、在你的项目(edorm)的WEB-INF/web.xml的<web-app></web-app>中加入以下代码
<resource-ref>
<description>
Resource reference to a factory for java.sql.Connection
instances that may be used for talking to a particular
database that is configured in the server.xml file.
</description>
<res-ref-name>
jdbc/edorm
</res-ref-name>
<res-type>
javax.sql.DataSource
</res-type>
<res-auth>
Container
</res-auth>
</resource-ref>

注意,这里的“jdbc/edorm”必须与上面配置的一样
附Java类方法:
/**
* 获得数据库连接
*
* @return
*/
public static Connection getCon() {
try {
Connection conn = null;
Context initCtx=new InitialContext();
conn = ((DataSource)initCtx.lookup("java:comp/env/jdbc/edorm")).getConnection();
conn.setAutoCommit(false);
return conn;
} catch (SQLException e) {
System.out.println(e.getMessage());
} catch (Exception e) {
// System.out.println("出现错误");
}
return null;// */
}

http://www.niftyadmin.cn/n/1036120.html

相关文章

小白的Dao层、Service层、Impl层、utils层、annotation层、pojo层、test层见解

Dao层 dao层叫数据访问层&#xff0c;全称为data access object&#xff0c;属于一种比较底层&#xff0c;比较基础的操作&#xff0c;具体到对于某个表、某个实体的增删改查&#xff0c;对外提供稳定访问数据库的方法Service层 Service是管理具体的功能的接口Impl层 impl层…

WebView加载本地加载网络资源

Android webview使用详解 1. 打开网页时不调用系统浏览器&#xff0c; 而是在本WebView中显示&#xff1a; 复制代码 mWebView.setWebViewClient(new WebViewClient(){ Override public boolean shouldOverrideUrlLoading(WebView view, String url) { …

Android动画分类及编写方式(view Animation/Tween Animation)视图动画(一个对象的变形)

Android动画分类 1.Property Animation属性动画 viewAnimation objectAnimation 2.View Animation/Tween Animation视图动画 AlphaAnimation 渐变动画 RotateAnimation旋转动画 ScaleAnimation缩放动画 TranslateAnimation位移动画 3.Drawable Animation/Frame Anim…

CrashLog

异常处理类 java的Thread中有一个UncaughtExceptionHandler接口&#xff0c;该接口的作用主要是为了 当 Thread 因未捕获的异常而突然终止时&#xff0c;调用处理程序。接口下面有setDefaultUncaughtExceptionHandler(Thread.UncaughtExceptionHandler eh)方法,方法主要作用为设…

底部导航栏点击跳转fragment

网上找了很多底部导航栏fragment切换&#xff0c;感觉各种方法都试了&#xff0c;下面是我自己整理的&#xff0c;希望能帮到大家。 &#xff08;1&#xff09;点击图片变色的xml文件写好。图片自己处理好。一个为例&#xff0c;其三个同理。 <?xml version"1.0"…

NavigationBar的第二中方法,图片变色,文字不变色

同上一篇的类似&#xff0c;但有不同之处&#xff0c;大家可以做比较&#xff0c;根据自己的需求学习使用。 &#xff08;1&#xff09;图片点击的xml文件 <?xml version"1.0" encoding"utf-8"?> <selector xmlns:android"http://schemas…

listView的可重用机制对性能的影响

ListView的Adapter的作用如下图所示&#xff1a; Adapter的作用就是ListView界面与数据之间的桥梁&#xff0c;当列表里的每一项显示到页面时&#xff0c;都会调用Adapter的getView方法返回一个View。想过没有&#xff1f; 在我们的列表有1000000项时会是什么样的&#xff1f;是…

ListView 关于Adapter 本地文件中解析json数据完整例子

第一步:布局文件 theme.xml <?xml version"1.0" encoding"utf-8"?> <LinearLayout xmlns:android"http://schemas.android.com/apk/res/android"android:orientation"vertical"android:layout_width"fill_parent&quo…