📄 usertest.java
字号:
package org.xjtu.testjdbc.test;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.PreparedStatement;
import org.xjtu.testjdbc.dbaccess.DBaccess;
public class UserTest {
private String sql = "select user_name ,user_pwd from " +
"tbuser2 where user_name = ? and user_pwd = ? ";
public boolean TestLogin(String username,String pwd)
{
boolean b = false;
DBaccess dbaccess = new DBaccess();
dbaccess.connDB();
Connection conn = dbaccess.getConn();
PreparedStatement stmt = null;
ResultSet rs = null;
try {
stmt = conn.prepareStatement(sql);
//绑定参数
stmt.setString(1,username);
stmt.setString(2,pwd);
//不需要再执行sql语句
rs = stmt.executeQuery();
while (rs.next())
{
b = true;
break;
}
} catch (SQLException e) {
e.printStackTrace();
}
finally
{
try {
rs.close();
stmt.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
return b;
}
/**
* @param args
*/
public static void main(String[] args) {
UserTest test = new UserTest();
System.out.print(test.TestLogin("a' or '1' = '1","a' or '1' = '1" ));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -