Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/393.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android Studio Oracle JDBC,不断为resultSet获取null_Java_Android_Oracle_Jdbc - Fatal编程技术网

Java Android Studio Oracle JDBC,不断为resultSet获取null

Java Android Studio Oracle JDBC,不断为resultSet获取null,java,android,oracle,jdbc,Java,Android,Oracle,Jdbc,我正在为我的高中项目工作,我遇到了一个问题。出于某种原因,当我试图从数据库中提取用户的名字和姓氏时,我总是得到空值。我知道JDBC工作正常,因为我们的登录工作正常。这是我的一些代码,告诉你发生了什么 帐户片段 public class AccountFragment extends Fragment { View rootview; @Nullable @Override public View onCreateView(LayoutInflater inflat

我正在为我的高中项目工作,我遇到了一个问题。出于某种原因,当我试图从数据库中提取用户的名字和姓氏时,我总是得到空值。我知道JDBC工作正常,因为我们的登录工作正常。这是我的一些代码,告诉你发生了什么

帐户片段

public class AccountFragment extends Fragment {
    View rootview;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        rootview = inflater.inflate(R.layout.fragment_account, container, false);
        return rootview;
    }

    public void onViewCreated(View view, Bundle savedInstanceState){
        super.onViewCreated(view, savedInstanceState);
        // initialize your views

        TextView mTextView1 = (TextView)view.findViewById(R.id.user_name);
        mTextView1.setText(UserLoginInfo.fName + " " + UserLoginInfo.lName);


        TextView mTextView2 = (TextView)view.findViewById(R.id.user_email);
        mTextView2.setText(UserLoginInfo.userEmail);

    }
}
UserLoginInfo类

public class UserLoginInfo {
public static String userEmail;
public static String fName;
public static String lName;


public UserLoginInfo() throws SQLException {

    try {
        Connection conn = ConnectionManager.getConnection();

        Statement st = null;

        st = conn.createStatement();

        ResultSet resultSet = null;

        if(st!=null)
            resultSet = st.executeQuery("SELECT * FROM userinfo WHERE email=" + userEmail + "'");
        if(resultSet!=null) {
            while (resultSet.next()) {
                fName = resultSet.getString("firstname");
                lName = resultSet.getString("lastname");
            }
        }

        resultSet.close();
        st.close();
    } catch(SQLException e) {
        e.printStackTrace();
    }



}
请记住,登录确实有效。所以我不明白为什么fName和lName的值总是为null。任何帮助都将不胜感激。谢谢

在查询字符串
“从userinfo中选择*,其中email=“+userEmail+””
,有一个“缺少”

顺便说一句,像那样使用
executeQuery
是个糟糕的主意。它为SQL注入攻击打开了大门。改用准备好的语句。

ResultSet.next()移动到下一行。我想,所有相应的数据都在同一行中。所以你不需要第二个时间。是的,我在一个单独的类中尝试过这样做,但仍然不起作用。请将你的查询添加到问题中。设置getString后fName是否为null,或者仅仅因为代码的这一部分没有执行?此函数返回什么:true或false?您可以从SQL*Plus或任何其他DB查看器执行查询吗?它是否为
firstname
返回值?感谢您注意到这一点,但它仍然不起作用。我对使用JDBC还是有点陌生,但我可能会尝试使用prepared语句。你能在一个独立的java应用程序中运行UserLoginInfo类吗,因为它不依赖于其他与android相关的东西,看看结果会是什么?