java吧 关注:1,240,719贴子:12,714,596
  • 4回复贴,共1

大神帮看下,一个问题搞了两天了

只看楼主收藏回复

package jdbcb;
import java.sql.SQLException;
import java.util.Scanner;
/*1创建文本录入监听
* 2使用jdbc技术验证用户登录信息是否正确,并给出回馈
*
*
* */
public class Userload {
/**
* @param args
* @throws ClassNotFoundException
* @throws SQLException
*/
public static void main(String[] args) throws ClassNotFoundException,
SQLException {
// TODO Auto-generated method stub
Scanner sn = new Scanner(System.in);
System.out.println("请输入用户名");
String sid = sn.nextLine();
System.out.println("请输入密码");
String sname = sn.nextLine();
DoUserload dl = new DoUserload();
User user = dl.finderuse(sid, sname);
if (user != null) {
System.out.println("欢迎您" + user.getsname());
} else {
System.out.println("用户或密码错误");
}
}
}
package jdbcb;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ResourceBundle;
public class Gongju {
private static String driverClass;
private static String url;
private static String user;
private static String password;
static {
ResourceBundle rb = ResourceBundle.getBundle("dengluxitong");
driverClass = rb.getString("driverClass");
url = rb.getString("url");
user = rb.getString("user");
password = rb.getString("password");
try {
Class.forName(driverClass);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static Connection getConnection() throws SQLException {
return DriverManager.getConnection(url, user, password);
}
public static void closeAll(Connection conn, Statement st, ResultSet rs)
{
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
rs= null;
}
if (st != null) {
try {
st.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
st = null ;
}
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
conn= null;
}
}
}
package jdbcb;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import jdbcb.Userload;
//@SuppressWarnings("unused")
public class DoUserload {
public User finderuse(String sid, String sname) throws SQLException {
Connection conn = null;
Statement st = null;
ResultSet rs = null;
User u = null;
try {
conn = Gongju.getConnection();
st = conn.createStatement();
String sql = "select * from stuu where sid='" + sid
+ "' and sname='" + sname + "'";
rs = st.executeQuery(sql);
if (rs.next()) {
u = new User();
u.setsid(rs.getString(1));
u.setsname(rs.getString(2));
u.setage(rs.getInt(3));
u.setgender(rs.getString(4));
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
Gongju.closeAll(conn, st, rs);
}
return u;
}
}
package jdbcb;
public class User {
private String sid;
private String sname;
private int age;
private String gender;
User() {
}
public String getsid() {
return sid;
}
public void setsid(String sid) {
this.sid = sid;
}
public String getsname() {
return sname;
}
public void setsname(String sname) {
this.sname = sname;
}
public int getage() {
return age;
}
public void setage(int age) {
this.age = age;
}
public String getgender() {
return gender;
}
public void setgender(String gender) {
this.gender = gender;
}
}


IP属地:中国香港1楼2017-06-15 07:21回复
    求大神帮看看


    IP属地:中国香港来自Android客户端2楼2017-06-15 07:25
    回复
      给大神跪了


      IP属地:中国香港来自Android客户端3楼2017-06-15 07:25
      回复
        别沉


        IP属地:中国香港来自Android客户端4楼2017-06-15 07:36
        回复
          长跪不起


          IP属地:中国香港来自Android客户端5楼2017-06-15 08:16
          回复