参数索引超出范围(1>参数个数,为0)

编程入门 行业动态 更新时间:2024-10-26 14:31:58
本文介绍了参数索引超出范围(1>参数个数,为0)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

参数索引超出范围(1>参数个数,为0) 我尝试过: 这是我的代码。表用户包含3行。有用户名和密码。它给我的错误如下:

Parameter index out of range(1> number of parameters,which is 0) What I have tried: This is my code.The table users contains 3 rows.having username and password.It is giving me the error as:

java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0). String DRIVER = "com.mysql.jdbc.Driver"; Class.forName(DRIVER).newInstance(); String url="jdbc:mysql://localhost:3306/regis?user=root&password=fraze"; Connection Conn = DriverManager.getConnection(url); String strSQL = "select username,password from users where username like '%s'; PreparedStatement statement = Conn.prepareStatement(strSQL); statement.setString(1, user); statement.setString(2, pass); ResultSet Rs= statement.executeQuery(strSQL); if(myRs.next()){ out.println("Login Succesful! A record with the given user name and password exists"); } else { out.println("Login Failed. No records exists with the given user name and password"); } statement.close();

我想要如果输入的用户名和密码是否正确,请与数据库进行核实。任何人都可以建议做出适当的更改。

I want to verify with the database if the username and password entered are correct or not. Could any one suggest as what would be appropriate changes that are to be made.

推荐答案

我昨天在你的问题中解释了你需要做什么,甚至给你链接到Select子句的文档。那你为什么现在这样做呢?您需要执行以下操作: - 创建一个SELECT子句以在此用户标识的数据库中查找记录,而不是像此一样的用户标识,但只有这一个。 - 如果找到了用户标识,则创建密码的盐渍哈希(我昨天给你的链接)并将其与数据库中的密码进行比较。 - 如果这两个测试都成功,那么继续,你有一个有效的登录。 - 如果找不到用户标识,或者密码不匹配,则拒绝登录尝试。但是不要告诉用户密码错误,这会给黑客提供太多信息。 I explained what you need to do in your question yesterday, and even gave you the link to the documentation for the Select clause. So why are you now doing it another incorrect way? You need to do the following: - Create a SELECT clause to find the record in the database for this userid, not userids that are like this one, but only this exact one. - If the userid is found then create a salted hash of the password (link I gave you yesterday) and compare that with the one in the database. - If both those tests succeed then continue, you have a valid login. - If the userid is not found, or the passwords do not match then reject the login attempt. But do not tell the user that the password is wrong, that gives hackers too much information.

更多推荐

参数索引超出范围(1>参数个数,为0)

本文发布于:2023-10-18 10:35:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1503980.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:参数   个数   索引   gt

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!