请问一个tomcat创建数据源的问题,我在web项目的meta-INF下配置了context-xml文件配置了jndi数据源,
,可是我并没有将mysql-connector-java-5.1.7-bin.jar和commons-dbcp-1.2.2.jar放在tomcat的lib目录下,后来测试...
,可是我并没有将mysql-connector-java-5.1.7-bin.jar和commons-dbcp-1.2.2.jar放在tomcat的lib目录下,后来测试还是对的
我是通过一个servlet来测试的
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
try {
//org.springframework.web.context.ContextLoaderListener
Context context = new InitialContext();
DataSource ds = (DataSource)context.lookup("java:/comp/env/jdbc/oa");
Connection connection = ds.getConnection();
Statement statement = connection.createStatement();
ResultSet rSet = statement.executeQuery("select *from admin");
while (rSet.next()) {
System.out.println(rSet.getString("adminid"));
}
} catch (NamingException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
System.out.println("hello");
}
然后访问这个servlet是正常运行的,我记得以前好像必须将connector-java-5.1.7-bin.jar和commons-dbcp-1.2.2.jar放在tomcat的lib目录下,否则tomcat是会找不到的,不知今天怎么就找到了,希望大家告诉我一下为什么这样可以找到 展开
我是通过一个servlet来测试的
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
try {
//org.springframework.web.context.ContextLoaderListener
Context context = new InitialContext();
DataSource ds = (DataSource)context.lookup("java:/comp/env/jdbc/oa");
Connection connection = ds.getConnection();
Statement statement = connection.createStatement();
ResultSet rSet = statement.executeQuery("select *from admin");
while (rSet.next()) {
System.out.println(rSet.getString("adminid"));
}
} catch (NamingException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
System.out.println("hello");
}
然后访问这个servlet是正常运行的,我记得以前好像必须将connector-java-5.1.7-bin.jar和commons-dbcp-1.2.2.jar放在tomcat的lib目录下,否则tomcat是会找不到的,不知今天怎么就找到了,希望大家告诉我一下为什么这样可以找到 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询