jsp登录界面连接SQL

来源:百度知道 编辑:UC知道 时间:2024/05/28 05:07:56
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<%!
public String codeToString(String str)
{//处理中文字符串的函数
String s=str;
try
{
byte tempb[]=s.getBytes("ISO-8859-1");
s=new String(tempb);
return s;
}catch(Exception e)
{return s;}
}
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title></title>
</head>
<body>
<%
String name=codeToString(request.getParameter("name"));
String pw=codeToString(request.getParameter("password"));
Connection con=null;
PreparedStatement stat;
ResultSet rs;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(ClassNotFoundExcepti

stat=con.prepareStatement("select*from useInfo where name=? and number=?");改为
stat=con.prepareStatement("select * from useInfo where name=? and number=?");试试
还有错误的话你把异常贴出来才好看
找不到驱动
如果你是用jdk自带的驱动的话就和你开发环境有关了
建议你用myeclipse或者其他IDE工具
如果不用的话就要配置环境变量
同时tomcat用安装版的,不要用解压版的

为什么不直接用jdbc?

sql语句问题
select*from useInfo where name=? and number=?");
连到一起了
把*与旁边两个单词分开写

con.prepareStatement("select*from useInfo where name=? and number=?");
换成con.prepareStatement("select * from useInfo where name=? and number=?");看看