jsp如何连接数据库?
exceptionorg.apache.jasper.JasperException:ExceptioninJSP:/test.jsp:63:<html>4:<body>...
exception
org.apache.jasper.JasperException: Exception in JSP: /test.jsp:6
3: <html>
4: <body>
5: <%
6: Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
7: String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs";
8: String user="sa";
9: String password="";
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:504)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
javax.servlet.ServletException: com.microsoft.jdbc.sqlserver.SQLServerDriver
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:858)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791)
org.apache.jsp.test_jsp._jspService(test_jsp.java:84)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802) 展开
org.apache.jasper.JasperException: Exception in JSP: /test.jsp:6
3: <html>
4: <body>
5: <%
6: Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
7: String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs";
8: String user="sa";
9: String password="";
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:504)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
javax.servlet.ServletException: com.microsoft.jdbc.sqlserver.SQLServerDriver
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:858)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791)
org.apache.jsp.test_jsp._jspService(test_jsp.java:84)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802) 展开
6个回答
展开全部
你想连接什么数据库啊
这是Access的
<%
dim conn
dim connstr
on error resume next
connstr="DBQ="+server.mappath("database/bo_data.mdb")+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
set conn=server.createobject("ADODB.CONNECTION")
if err then
err.clear
else
conn.open connstr
if err then
err.clear
end if
end if
%>
sql sever2000的
set conn=server.createobject("adodb.connection")
conn.open "Driver={SQL Server};server=服务器地址;UID=sa;Pwd=;database=pubs"
set rs=server.createobject("adodb.recordset")
set rs=conn.Execute("select * from employee")
while not rs.eof
……
wend
rs.close
set rs=nothing
conn.close
set conn=nothing
这是Access的
<%
dim conn
dim connstr
on error resume next
connstr="DBQ="+server.mappath("database/bo_data.mdb")+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
set conn=server.createobject("ADODB.CONNECTION")
if err then
err.clear
else
conn.open connstr
if err then
err.clear
end if
end if
%>
sql sever2000的
set conn=server.createobject("adodb.connection")
conn.open "Driver={SQL Server};server=服务器地址;UID=sa;Pwd=;database=pubs"
set rs=server.createobject("adodb.recordset")
set rs=conn.Execute("select * from employee")
while not rs.eof
……
wend
rs.close
set rs=nothing
conn.close
set conn=nothing
展开全部
import java.sql.*;
public class JdbcOdbc_Con
{
String dbDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String strCon = "jdbc:odbc:sts";
Connection con = null;
ResultSet rs = null;
Statement stmt = null;
public JdbcOdbc_Con()
{
try
{
Class.forName(dbDriver);
}
catch(java.lang.ClassNotFoundException e)
{
System.err.println("数据库驱动程序加载失败,异常为:" + e.getMessage());
}
finally
{
System.out.println("驱动程序加载成功");
}
}
然后你在odbc那里配好数据源!!这里是sts
public class JdbcOdbc_Con
{
String dbDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String strCon = "jdbc:odbc:sts";
Connection con = null;
ResultSet rs = null;
Statement stmt = null;
public JdbcOdbc_Con()
{
try
{
Class.forName(dbDriver);
}
catch(java.lang.ClassNotFoundException e)
{
System.err.println("数据库驱动程序加载失败,异常为:" + e.getMessage());
}
finally
{
System.out.println("驱动程序加载成功");
}
}
然后你在odbc那里配好数据源!!这里是sts
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
楼上的asp的吧,jsp的哪个教程里都有
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
和在JAVA桌面程序里的代码是一样的 放到<% 这里 %>就行噻
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
找本jsp书,不同的数据库连接方法不一样
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你没有导入数据库连接所必须的jar包.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询