我正在学校的高级项目上工作,我遇到了问题。出于某种原因,当我尝试将用户的名字和姓氏从我们的数据库中删除时,我一直收到空。我知道JDBC正常工作,因为我们的登录工作正常。这是我的一些代码,可以告诉你发生了什么事情。Android Studio Oracle 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获得空值。任何帮助将不胜感激。谢谢!!
ResultSet.next()移到下一行。我想,所有相应的数据都在同一行。所以你不需要第二次。 – Qualtagh
是的,我已经尝试在单独的课程中做到这一点,它仍然无法正常工作。 –
请将您的查询添加到问题中。 – Qualtagh