0
我正在嘗試訪問部署tomcat服務器的計算機上創建的MS-Access dsn。使用上下文連接到Tomcat中的MS Access
正常代碼:
連接CON =的DriverManager.getConnection(sun.jdbc ....)沒有工作。
所以我得到了解決方案的地方,它可以使用上下文來完成。我當前的代碼如下:
<%@ page import="java.sql.*" %>
<%@ page import="javax.naming.*" %>
<%@ page import="javax.sql.*" %>
<%
String un=request.getParameter("un");
String ps=request.getParameter("ps");
out.println("Redirected from index page<br>");
%>
<%
Connection con=null;
Statement st=null;
ResultSet rs=null;
try{
Context initCtx=new InitialContext();
Context envCtx = (Context)initCtx.lookup("java:comp/env");
DataSource ds=(DataSource)envCtx.lookup("jdbc/product");
con=ds.getConnection();
st=con.createStatement();
rs=st.executeQuery("select * from login where User_name='"+un+"' and password='"+ps+"' ");
if(rs.next())
{
session.setAttribute("user",un);
out.println("<html> <body onload='f.submit()'> <form action='dis.jsp' name='f' </form></body></html> ");
}
else
{
out.println("<h1> Kindly check your username and password </h1>");
}
}
catch(Exception ex)
{
out.println(ex.getMessage());
}
%>
但點擊提交時,它顯示了以下錯誤:
Redirected from index page
Name [jdbc/product] is not bound in this Context. Unable to find [jdbc].
幫我..我是新來的..
問候。
沒有在您指定的context.xml中的JDBC DataSource? – 2014-09-19 06:11:57
嗯..對不起..我複製了代碼從web ..沒有什麼像context.xml ..請幫助 – SurajS 2014-09-19 06:18:05