注册 登录
编程论坛 SQL Server论坛

sql 插入两个字段,但是查询的时候只显示一个字段是怎么回事啊

tqw 发布于 2017-10-13 00:19, 1782 次点击
用jsp做一个系统,做注册的时候,新增的两个字段(用户,密码)成功了,但是发现在sql中新增的两个字段,在查询的时候只显示一个字段,然后登陆失败是怎么回事啊。
程序代码:
package dao.impl;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import dao.UserDao;

public class UserDaoImpl implements UserDao{
    Connection conn=null;
    PreparedStatement pstmt=null;
    ResultSet rs=null;
    @Override
    public int insert(String username,String password) {
        int i=0;
        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            conn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","user2","admin");
            pstmt=conn.prepareStatement("insert into users values(?,?)");
            pstmt.setString(1,username);
            pstmt.setString(2,password);
            i = pstmt.executeUpdate();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        try {
            if(rs!=null)rs.close();
            if(pstmt!=null)pstmt.close();
            if(conn!=null)conn.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return i;
    }
    @Override
    public boolean login(String username,String password) {
        boolean b=false;
        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            conn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","user2","admin");
            pstmt=conn.prepareStatement("select * from users where username=? and password=?");
            pstmt.setString(1,username);
            pstmt.setString(2,password);
            //pstmt 执行sql语句

            //pstmt.execute();//适用于增 删 改  查
            //pstmt.executeUpdate();//适用于  增 删  改 ==>int  受影响的行数
            rs=pstmt.executeQuery();//适用于 select  ==>resultSet
            if(rs.next()){
                b=true;
            }
        } catch (ClassNotFoundException e) {

            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        try {
            if(rs!=null)rs.close();
            if(pstmt!=null)pstmt.close();
            if(conn!=null)conn.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return b;
    }

}
只有本站会员才能查看附件,请 登录

求助求助
1 回复
#2
mywisdom882017-10-13 17:47
你是不是传空参数给密码字段
1