Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Servlet/JSP/JSF/JavaFX Script » 精华  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
reply to postflat modethreaded modego to previous topicgo to next topicgo to back
作者 求大家帮我看看这段程序!!!!!
zyb3511





发贴: 3
于 2006-08-24 09:01 user profilesend a private message to userreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我是个java初学者~我现在要做一个数据库的查询~但就是调试不成功~这些源码很多也是复制别人的.请大家帮我看看问题出在哪里吧~万分感谢
<%@ page contentType="text/html; charset=gb2312" %>

<%@ page import="com.mysql.jdbc.Driver" %>

<%@ page import="java.sql.*" %>
<%
request.getSession(true); // 启用 Session 功能

String USER = request.getParameter("username"); // 取得使用者输入的账号资料
String PASS = request.getParameter("password"); // 取得使用者输入的密码资料

// 以下将宣告与数据库联系的程序
String driverName="com.mysql.jdbc.Driver";

String userName="root";

String userPasswd="123";

String dbName="test";

String tableName="table3";

String url="jdbc:mysql://localhost/"+dbName+"?user="+userName+"&password="+userPasswd;

Class.forName("com.mysql.jdbc.Driver").newInstance();

Connection connection=DriverManager.getConnection(url);

Statement statement = connection.createStatement();
ResultSet rs=null;

//获得数据结果集合

ResultSetMetaData rmeta = rs.getMetaData();

//确定数据集的列数,亦字段数

int numColumns=rmeta.getColumnCount();
%>

<html>
<head><title>密码验证</title></head>

<body bgcolor="#ccccff">
<%
String check = "SELECT name, pass FROM tableName WHERE name= '" +USER + "' AND pass= '" + PASS +"' ";
rs=statement.executeQuery(check);

String Test1 = null; //初始化
String Test2 = null; // 初始化
// 以下将逐一取出数据库中的使用者账户,密码
if (rs.next())
{
Test1 = rs.getString("name"); // 取出数据库中的使用者账号
Test2 = rs.getString("pass"); // 取出数据库中的使用者密码
}
%>

<%
out.println(check);
if(USER.equals(Test1) && PASS.equals(Test2))
{
// 验证成功,将使用者的账号、密码存放到 Session 物件中
session.setAttribute("NAME",request.getParameter("username"));
session.setAttribute("PWD",request.getParameter("password"));


rs.close();
statement.close();
connection.close();

response.sendRedirect("2.jsp");}

else
{

rs.close();
statement.close();
connection.close();

response.sendRedirect("error.jsp");
}
%>
</body>
</html>




话题树型展开
人气 标题 作者 字数 发贴时间
2335 求大家帮我看看这段程序!!!!! zyb3511 2222 2006-08-24 09:01
1934 Re:求大家帮我看看这段程序!!!!! zcjl 258 2006-08-24 10:03
1954 Re:求大家帮我看看这段程序!!!!! zyb3511 11 2006-08-24 13:44
1909 Re:求大家帮我看看这段程序!!!!! why 79 2006-08-24 18:50
1985 Re:求大家帮我看看这段程序!!!!! gaoxt1983 27 2006-08-25 12:22
2044 Re:求大家帮我看看这段程序!!!!! 熙城候 4 2006-09-06 10:43

reply to postflat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923