<%Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=STUDENT";
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=STUDENT";
解决方案 »
- myeclipse导出war包无法部署到jboss5.1中
- 怎么样取arraylist的前N条数据
- 急,在线等!jsp+mysql连接报错!
- session设置,不能正确读取
- 100分!!!!!!!!!!!!!!用weblogic部署web应用(此应用在tomcat下部署成功)时console说部署成功,但访问http://localhost:700
- 动态生成的shtml,编码为什么默认是西欧??????? 十万火急,解决者满分!!!!!!!!
- 怎样设置才能在JDK+Tomcat5、JBuilder9这两种方式中都能使用JSTL呀?
- 这样的问题如何解决呀,回答就有分,郁闷,谁来帮我----谢谢先!
- java.text.ParseException: Unparseable date: "2014-09-24 17:07:23"
- 哪位大神帮帮我!!!
- 问个button和js的关系
- 请大家帮个忙吧~~~~!!!
<%@ page contentType="text/html; charset=GBK" language="java" import="java.sql.*" errorPage=""%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=gb2312">
<title>
数据查询
</title>
<style type="text/css">
<!--
body{
background-color:#CCCCFF;
}
.style1{font-size:24px}
.style2{color:#CCCCFF}
-->
</style>
</head>
<body>
<div align="center" class="style1">
<p>请输入要查询的课程号</p>
<form name="form1" method="POST" action="show.jsp" >
<input type="text" name="id">
<input type="submit" name="Submit" value="查询">
</form>
<p><span class="style2"></span></p>
</div>
</body>
</html>
show.jsp:
<%@ page contentType="text/html; charset=GBK" language="java" import="java.sql.*" errorPage=""%>
<html>
<head>
<title>
show
</title>
</head>
<body >
<div align="center"><span class="style2">以下是课程的详细信息</span>
<%Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=STUDENT";
String user="sa";
String password="";
Connection conn=DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
String id=request.getParameter("Cno");
String sql="select * from Course where Cno="+id;
ResultSet rs=stmt.executeQuery(sql);
%>
<center class="style1">
</div>
<hr>
<%
while(rs.next())
{
session.setAttribute("Cno",rs.getString("Cno"));
%>
<p align="center">课程号:<%=rs.getString("Cno")%></p>
<p align="center">课程名:<%=rs.getString("Cname")%></p>
<p align="center">先行课:<%=rs.getString("Cpno")%></p>
<p align="center">学分:<%=rs.getString("Ccredit")%></p>
<%
}
rs.close();
stmt.close();
conn.close();
%>
<p align="center"><input type="button" id="back" name="back" value="返回"
onClick="javascript:history.go(-1)"></p>
</body>
</html>
<html>
<head>
<title>
show
</title>
</head>
<body >
<div align="center"> <span class="style2">以下是课程的详细信息 </span>
<%
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=STUDENT";
String user="sa";
String password="";
Connection conn=DriverManager.getConnection(url,user,password);
System.out.println("conn:"+conn);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
String id=request.getParameter("Cno");
String sql="select * from Course where Cno="+id;
ResultSet rs=stmt.executeQuery(sql);
System.out.println("rs:"+rs);
%>
<center class="style1">
</div>
<hr>
<%
while(rs.next())
{
session.setAttribute("Cno",rs.getString("Cno"));
%>
<p align="center">课程号: <%=rs.getString("Cno")%> </p>
<p align="center">课程名: <%=rs.getString("Cname")%> </p>
<p align="center">先行课: <%=rs.getString("Cpno")%> </p>
<p align="center">学分: <%=rs.getString("Ccredit")%> </p> <%
}
rs.close();
stmt.close();
conn.close();
} catch (Exception e) {
System.out.println("e:"+e.getMessage());
}
%>
<p align="center"> <input type="button" id="back" name="back" value="返回"
onClick="javascript:history.go(-1)"> </p>
</body>
</html>
javax.servlet.ServletException: com.microsoft.jdbc.sqlserver.SQLServerDriver
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)
org.apache.jsp.show_jsp._jspService(show_jsp.java:121)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
jdbc配置应该没有问题,我做数据遍历时能连接上,连接的代码都是一样的