免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 830 | 回复: 0
打印 上一主题 下一主题

jboss4。0下mysql数据源的配置 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-04-18 22:08 |只看该作者 |倒序浏览

花了一个小时的时间,搞了一下jboss4。0下mysql数据源的配置。下面是一些具体过程
1、首先安装mysql数据库并将其驱动程序考到jboss的server\default\lib下面
2、将mysql-ds.xml文件放置到server\default\deploy下面
    内容如下:
   
  
    MySqlDS
    jdbc:mysql://localhost:3306/test
    org.gjt.mm.mysql.Driver
    root
    qwe123
      
      
         mySQL
      
  
3、建立一个自己的war包 testds.war
    内含有META-INF/jbosscmp-jdbc.xml, 重载默认的数据源
   
       java:/MySqlDS
       mySql
  
4、建立一个servlet进行测试,放在上面的包中
package test;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.*;
import javax.naming.*;
import javax.sql.*;
import java.io.*;
/**
* @author Administrator
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class myservlet extends HttpServlet {
/* (non-Javadoc)
  * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
  */
protected void doGet(HttpServletRequest req, HttpServletResponse res)
   throws ServletException, IOException {
  // TODO Auto-generated method stub
  //super.doGet(arg0, arg1);
  PrintWriter out = res.getWriter();
  Connection conn    = null;
  Statement  stmt    = null;
  ResultSet  rs      = null;
  try {
   Context    initCtx = new InitialContext();
      DataSource ds  = (DataSource)initCtx.lookup("java:/MySqlDS");
           conn  = ds.getConnection();
   if (conn != null)
    out.println("ok");
   else
    out.println("error");
  }
  catch(Exception e)
  {
   System.out.println("Exception"+e);
  }
}
}
web.xml
  
    my Servlet
    test.myservlet
  
  
    my Servlet
    /*
  
呵呵。启动jboss,在浏览器中键入
http://localhost:8080/testds/
  显示OK,成功!!!
   



本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/17667/showart_101801.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP