stmt=con.createStatement();出错

来源:百度知道 编辑:UC知道 时间:2024/05/31 18:51:04
<%@ page contentType="text/html; charset=GBK" %>
<%@ page import="java.sql.*" %>
<html>
<head>
<title>
login_do
</title>
</head>
<body bgcolor="#ffffff">
<html>
<body>
<%
String un = request.getParameter("username");
String ps = request.getParameter( "password");
Connection con=DriverManager.getConnection ("jdbc:odbc:user","sa","");
stmt=con.createStatement();
ResultSet rs=stmt.executeQuery( "select*from t_user where username= ' "+un+ " ' and password= ' "+ps+ " ' ");
if(rs.next())
{
out.println( "登录成功! ");
}else
{
out.println( "登录失败! ");

stmt=con.createStatement();
应该是Statement stmt = con.createStatement();

ResultSet rs=stmt.executeQuery( "select*from t_user where username= ' "+un+ " ' and password= ' "+ps+ " ' ");
写成:
ResultSet rs=stmt.executeQuery( "select * from t_user where username= ' "+un+ " ' and password= ' "+ps+ " ' ");

ResultSet rs=stmt.executeQuery( "select*from t_user where username= ' "+un+ " ' and

你把你的这句SQL 打印出来,看能不能在查询分析器中跑,我想是不能的
select * from 是要空格的,呵呵

报异常了! 用try catch 包围就行了