我是tomcat5.1的,可是初步来
为什么??
为什么??
解决方案 »
- 使用JSP如何在上传文件时自动创建一个新的文件夹
- 100分求java,javascript 或jsp实现的进度条模式程序例子
- 怎样将表格的样式设置成像excel里面中间部分的那种?
- 疯了. 我今天弄了一天了.
- 基于J2EE的新蓝网络协同办公系统,请大家试用,顶者有分!
- 教关于文件下载zip的问题
- 如何在java操作微软的Office Web Component ???最好给个例子。
- 急救,在jsp页面保存xml文件时,对XML的语法检查问题
- weblogic连接池的问题,怎么解决?
- 正则表达式 两个汉字中间的字符串
- sqlserver->ORACLE
- 使用java+XML技术如何实现,请教高手
應該寫詳細點,
多做點測試。
javax.servlet.ServletException: Name jdbc is not bound in this Context
你的那些配置信息也是下面这样写的么?
JNDI Name: jdbc/mssql //你的名字也是这样写的么?
Data Source URL: jdbc:microsoft:sqlserver://192.168.0.52:1433;databaseName=abu
JDBC Driver Class:com.microsoft.jdbc.sqlserver.SQLServerDriver
User Name:abu
Password: abu
Max. Active Connections: 4
Max. Active Connections: 2
Max. Wait for Connection: 5000
Validation Query://可以不填
希望大家有条件都试试,我这里试了好几台机子了,都是好着的
当然配置文件我是不可能弄错的
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:867)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:800)
org.apache.jsp.index_jsp._jspService(index_jsp.java:456)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
root cause javax.servlet.jsp.JspException: Name jdbc is not bound in this Context
com.hawk.news.NewsInfoHandler.doStartTag(NewsInfoHandler.java:135)
org.apache.jsp.index_jsp._jspx_meth_new_NewsInfo_0(index_jsp.java:478)
org.apache.jsp.index_jsp._jspService(index_jsp.java:118)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
try{
Class.forName(this.ConnDriver);
this.conn = DriverManager.getConnection(this.ConnUrl);
}catch(Exception e){
System.out.println(e.getMessage().toString());
}创建statement的代码:
Connection conn = db.getconn();
Statement stmt = conn.createStatement();
Data Source URL: jdbc:microsoft:sqlserver://192.168.202.151:1433;DatabaseName=lx
JDBC Driver Class:com.microsoft.jdbc.sqlserver.SQLServerDriver
User Name:sa
Password:
Max. Active Connections: 4
Max. Active Connections: 2
Max. Wait for Connection: 5000
Validation Query://可以不填
点击Commit Changes后重新启动tomcat
建立test1.jsp,输入内容如下:
<%@ page import="javax.sql.*"%>
<%@ page import="javax.naming.*"%><%
DataSource ds = null;
try{
InitialContext ctx=new InitialContext();
ds=(DataSource)ctx.lookup("java:comp/env/jdbc/sqlserver ");
Connection conn = ds.getConnection();
Statement stmt = conn.createStatement();
String strSql = "select * from users";
ResultSet rs = stmt.executeQuery(strSql);
while(rs.next()){
System.out.println(rs.getString(1));
}
}
catch(Exception ex){
ex.printStackTrace();
}
%>
报错如下:
C:\tomcat\work\Catalina\localhost\test\org\apache\jsp\test1_jsp.java:51: cannot resolve symbol
symbol : class Connection
location: class org.apache.jsp.test1_jsp
Connection conn = ds.getConnection();
不知我如上配置是否正确.请指教,我是新手,有低级错误,不要笑我.
有問題可以在這邊討論。。不是很好?
你的直连也出错的话,可能是你的驱动没有放好位置或者MSSQL实例名的原因,你先把直接连的弄好,才能配置连接池的。你搜搜这里的帖子,有关于讲连不上MSSQL的解决方法的。Connection conn = db.getconn();
Statement stmt = conn.createStatement();//可能是没有取到连接,所以创建Statement时报错。
加上下面这个。
<%@ page import="java.sql.*"%>
<%@ page import="javax.naming.*"%>
这两个找不到,我装的是j2se版的,不是j2ee版的,是不是这个原因?
(说明:推荐给《程序员》杂志的文章只有没被采用,或者已经在杂志上发表了,才会审批通过。)