jsp
数据库我已经建立好了但是经过javabean查询不到数据库javabean代码
package kc.com;
import java.sql.*;
public class Login {
Connection con=null;
Statement stmt=null;
ResultSet rs=null;
public Login(){
try{
String url="jdbc:sqlserver://localhost:1433; DatabaseName=student";
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();con=DriverManager.getConnection(url,"sa","sa");
stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
}catch(Exception e){e.printStackTrace();}
}
public ResultSet search(String xm){
try{
rs=stmt.executeQuery("select * from stuinfo where 姓名='"+xm+"'");
}catch(Exception e){e.printStackTrace();}
return rs;
}
public void close(){
try{
rs.close();
stmt.close();
con.close();
}catch(Exception e){e.printStackTrace();}
}
}
jsp代码
<%@page contentType="text/html;charset=gb2312"%>
<%@page import="java.sql.*"%>
<%request.setCharacterEncoding("gb2312");%>
<jsp:useBean id="db" class="kc.com.Login" scope="page"/>
<form method="post" action="">
请输入你要查询的学生姓名:<input type="text" name=xm size=20>
<input type="submit" name="bt1" value="查找">
</form>
<%
ResultSet rs;
String xm=request.getParameter("xm");
if(xm!=null)
{
rs=db.search(xm);
out.println("<table border=2 align=center width=80% >");
out.println("<tr>");
out.println("<tr>学号</tr>");
out.println("<tr>姓名</tr>");
out.println("<tr>年龄</tr>");
out.println("</tr>");
while(rs.next())
{
out.println("<tr>");
out.println("<td>"+rs.getString(1)+"</td>");
out.println("<td>"+rs.getString(2)+"</td>");
out.println("<td>"+rs.getString(3)+"</td>");
out.println("</tr>");
}
out.println("</table>");
}
db.close();
%>
谢谢 --------------------编程问答-------------------- 不知道你要什么。 --------------------编程问答--------------------
貌似String url="jdbc:sqlserver://localhost:1433; DatabaseName=student";
1433;后面多了一个空格
补充:Java , Eclipse