我正在學校的高級項目上工作,我遇到了問題。出於某種原因,當我嘗試將用戶的名字和姓氏從我們的數據庫中刪除時,我一直收到空。我知道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