當前位置:首頁 » 操作系統 » java資料庫驗證

java資料庫驗證

發布時間: 2022-09-12 01:48:03

java鏈接mysql資料庫實現登陸驗證

//這是我以前寫的核對資料庫實現登陸的方法,你只看jdbc部分就好,我還特地給你加了點注釋
String sql = "select username,password from account";
String user = request.getParameter("user");
String pass = request.getParameter("password");
int j = 0;
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
conn = JDBCTools1.getConnection();
ps = conn.prepareStatement(sql);
rs = ps.executeQuery();
//從表中查詢獲取所有賬戶的用戶名&密碼的ResultSet 對象
while(rs.next()){
int i = 0;

String username[] = new String[10];//用戶名數組
String password[] = new String[10];//密碼數組
username[i] = rs.getString(1);
password[i] = rs.getString(2);
if(user.equals(username[i])&&pass.equals(password[i])){//比對
response.getWriter().print("you are welcome!");
j++;
}else if(user.equals(username[i])&&!pass.equals(password[i])){
response.getWriter().println("the realy password is :"+ username[i] +","+password[i]+"\r\n");
response.getWriter().println("and you password is :"+user +","+pass+" :so the username or password may not right");
j++;
}else{
continue;
}
i++;
}
if(j == 0){
response.getWriter().println("Your username may not be properly");
}
} catch (Exception e) {
e.printStackTrace();
}finally{
JDBCTools1.release(rs, ps, conn);
}
//這是我JDBCTools的getConnection方法
getConnection{
String driverClass = oracle.jdbc.driver.OracleDriver;
String jdbcUrl = jdbc:oracle:thin:@localhost:1521:orcl;
//你的資料庫的用戶名密碼
String user = null;
String password = null;
// 通過反射創建Driver對象
Class.forName(driverClass);
return DriverManager.getConnection(jdbcUrl, user, password);}
//這是我JDBCTools的release方法
public static void release(ResultSet rs, Statement statement,
Connection conn) {
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}

if (statement != null) {
try {
statement.close();
} catch (Exception e2) {
e2.printStackTrace();
}
}

if (conn != null) {
try {
conn.close();
} catch (Exception e2) {
e2.printStackTrace();
}
}
}

Ⅱ 向資料庫插入的數據不重復,如何用Java做驗證

String
name
=
xx(這里寫你獲取到的准備插入的name的值)
select
name
from
(這里寫你的表名)
where
name
=
xx;
ResustSet
rs
=
(執行上句話生成結果集)
if(rs.next()){
(這里寫發現重復時的操作)
]
else{
(這里寫正式的插入語句)
}

Ⅲ java程序怎麼驗證密碼

首先建立java程序與資料庫的連接
然後執行sql語句用資料庫驗證
select
count(賬號「密碼」
然後前台如果獲取到數據說明密碼正確
如果沒有數據則說明密碼錯誤

Ⅳ 向資料庫插入的數據不重復,如何用Java做驗證

String name = xx(這里寫你獲取到的准備插入的name的值)
select name from (這里寫你的表名) where name = xx;
ResustSet rs = (執行上句話生成結果集)
if(rs.next()){ (這里寫發現重復時的操作)
]
else{ (這里寫正式的插入語句)
}

Ⅳ java如何驗證用戶名是否存在於資料庫的代碼

發一句select * from ### for update到資料庫,取得一個ResultSet對象,遍歷這個對象,不斷獲取用戶名和密碼,做對比即可哇。

Ⅵ java編程:怎麼在jsp頁面輸入數據的時候驗證資料庫里是否有同名的值吖

用戶名<input type = "text" id="username" onBlur="post()">

jquery+ajax:
function post() {
alert($("#username").val());
$.ajax({
type:"POST",
url:"user.action",//後台注冊方法,包含校驗或者直接校驗,按照自己的來
data: "user.name=" +$("#username").val(),
dataType: "html" ,
success:callback //回調函數
}) ;
}
function callback(data) {
var a = parseInt(data);
if(a == 0) {
alert("注冊成功");
}
else if(a==1) {
alert("該用戶名已經存在");
}

大概可以寫成這樣。。。哦了不

Ⅶ java鏈接mysql資料庫實現登陸驗證

用swing連接資料庫就不需要odbc了,寫一個DBconnection和ResultSet的資料庫連接類就可以了,具體編寫的方法網上搜索就能找到,希望我的回答是你想要的。

Ⅷ java鏈接mysql資料庫實現登陸如何驗證

//這是我以前寫的核對資料庫實現登陸的方法,你只看jdbc部分就好,我還特地給你加了點注釋
String sql = "select username,password from account";
String user = request.getParameter("user");
String pass = request.getParameter("password");
int j = 0;
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
conn = JDBCTools1.getConnection();
ps = conn.prepareStatement(sql);
rs = ps.executeQuery();
//從表中查詢獲取所有賬戶的用戶名&密碼的ResultSet 對象
while(rs.next()){
int i = 0;

String username[] = new String[10];//用戶名數組
String password[] = new String[10];//密碼數組
username[i] = rs.getString(1);
password[i] = rs.getString(2);
if(user.equals(username[i])&&pass.equals(password[i])){//比對
response.getWriter().print("you are welcome!");
j++;
}else if(user.equals(username[i])&&!pass.equals(password[i])){
response.getWriter().println("the realy password is :"+ username[i] +","+password[i]+"\r\n");
response.getWriter().println("and you password is :"+user +","+pass+" :so the username or password may not right");
j++;
}else{
continue;
}
i++;
}
if(j == 0){
response.getWriter().println("Your username may not be properly");
}
} catch (Exception e) {
e.printStackTrace();
}finally{
JDBCTools1.release(rs, ps, conn);
}
//這是我JDBCTools的getConnection方法
getConnection{
String driverClass = oracle.jdbc.driver.OracleDriver;
String jdbcUrl = jdbc:oracle:thin:@localhost:1521:orcl;
//你的資料庫的用戶名密碼
String user = null;
String password = null;
// 通過反射創建Driver對象
Class.forName(driverClass);
return DriverManager.getConnection(jdbcUrl, user, password);}
//這是我JDBCTools的release方法
public static void release(ResultSet rs, Statement statement,
Connection conn) {
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}

if (statement != null) {
try {
statement.close();
} catch (Exception e2) {
e2.printStackTrace();
}
}

if (conn != null) {
try {
conn.close();
} catch (Exception e2) {
e2.printStackTrace();
}
}
}

Ⅸ 用java做了一個簡單的登陸窗口,已經連上資料庫,如何用資料庫驗證登陸的用戶名和密碼

public void actionPerformed(ActionEvent e)
{
if(e.getSource()==Enter)
{
String username , password;
username = name.getText();
password = pwd.getText();
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch (ClassNotFoundException ce)
{
JOptionPane.showMessageDialog(ss,ce.getMessage());
}
if(stu.isSelected())
{
try
{
Connection con = DriverManager.getConnection("jdbc:odbc:DS_121301_12","sa","");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select * from stu where ID='"+username+"' and Pwd='"+password+"'");
while(rs.next())
{
if((rs.getString("ID").equals(username))&&(rs.getString("Pwd").equals(password)))
{
JOptionPane.showMessageDialog(ss,"登陸成功");
Students stu = new Students();
}

else
{
JOptionPane.showMessageDialog(ss,"登錄失敗");
}

}

Ⅹ java登錄查詢資料庫驗證

調用你已經創建專門的連接資料庫的類和返回查詢數據的類的方法獲取資料庫連接 然後執行sql就可以了

熱點內容
手機怎麼修改wifi密碼名稱 發布:2025-07-05 06:46:13 瀏覽:378
阿里雲伺服器bt安裝 發布:2025-07-05 06:36:46 瀏覽:368
資料庫組別 發布:2025-07-05 06:15:53 瀏覽:711
我的世界伺服器怎樣設置新手裝備只能拿一次 發布:2025-07-05 06:15:53 瀏覽:985
緩存40集電視劇需要多少流量 發布:2025-07-05 05:56:44 瀏覽:64
iso怎麼解壓到u盤 發布:2025-07-05 05:49:02 瀏覽:890
php參數設置 發布:2025-07-05 05:49:00 瀏覽:995
javacharacter 發布:2025-07-05 05:38:36 瀏覽:735
伺服器pcid地址怎麼看 發布:2025-07-05 05:35:40 瀏覽:384
安卓系統賺錢靠什麼 發布:2025-07-05 05:28:06 瀏覽:159