比较来自sqlite数据库的数据已插入的数据

时间:2014-11-01 19:11:49

标签: android sqlite

我试图在ma app中进行注册活动,我想在用户输入学生ID时查看学生ID是否在数据库中,如果是,请注册 它说错了......所以我有错误...... 这是logcat后面的代码

     EditText st_id , st_pass, Pass_again;
 String student_id ,pass_ag ,pass;
 Button regs, cancel_reg;
  Context cxt,cxt2;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.registor);
        st_id=(EditText)findViewById(R.id.st_id);
        st_pass=(EditText)findViewById(R.id.st_pass);
        Pass_again=(EditText)findViewById(R.id.pass_again);
        cxt=this;
        regs=(Button)findViewById (R.id.regs) ;
        cancel_reg=(Button) findViewById(R.id.cancel_reg);
        regs.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                student_id=st_id.getText().toString();
                pass=st_pass.getText().toString();
                pass_ag=Pass_again.getText().toString();
                Getdata  info = new Getdata (cxt);
                info.open();
                String data=info.getdata();
            Cursor CR=info.getdata(cxt2);
                info.close();
                CR.moveToFirst();



                /*if(!(pass.equals(pass_ag) && (student_id.equals(CR.getString(0)))))
                {
                    Toast.makeText(getBaseContext(), "Password not match /n or student id not found", Toast.LENGTH_LONG).show();
                    st_id.setText("");
                    st_pass.setText("");
                    Pass_again.setText("");

                }
                else
                {
                    DataBaseopretions db =new DataBaseopretions(cxt);
            db.putinformation(db, student_id, pass , pass_ag);
            Toast.makeText(getBaseContext(), "Registrtion success", Toast.LENGTH_LONG).show();
            finish();
                }

            }
        });*/
                CR.moveToFirst();
                boolean loginstatus=false;
                String student = "";
                do{
                    if(!(pass.equals(pass_ag) && (student_id.equals(CR.getString(0))))){
                        loginstatus=true;
                        student=CR.getString(0);
                    }

                }while(CR.moveToNext());
                  if(loginstatus)
                  {
                      Toast.makeText(getBaseContext(), "Rigstretion sucsess--- \n Welcome"+ student, Toast.LENGTH_LONG).show();
                      Intent i= new Intent(Rigstretion.this ,Student_pag.class);
                        startActivity(i);
                  }
                  else
                  {
                      Toast.makeText(getBaseContext(), "Rigstretion failed---  wrong student id or password doesn't match", Toast.LENGTH_LONG).show();

                      finish();
                  }
            }
                  });

        cancel_reg.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                student_id=" ";
                pass=" ";
                pass_ag=" ";
                finish();
            }
        });


    }
}

logcat的

   11-01 18:54:51.204: E/AndroidRuntime(28496): FATAL EXCEPTION: main
11-01 18:54:51.204: E/AndroidRuntime(28496): java.lang.IllegalStateException: Cannot perform this operation because the connection pool has been closed.
11-01 18:54:51.204: E/AndroidRuntime(28496):    at android.database.sqlite.SQLiteConnectionPool.throwIfClosedLocked(SQLiteConnectionPool.java:962)
11-01 18:54:51.204: E/AndroidRuntime(28496):    at android.database.sqlite.SQLiteConnectionPool.waitForConnection(SQLiteConnectionPool.java:599)
11-01 18:54:51.204: E/AndroidRuntime(28496):    at android.database.sqlite.SQLiteConnectionPool.acquireConnection(SQLiteConnectionPool.java:348)
11-01 18:54:51.204: E/AndroidRuntime(28496):    at android.database.sqlite.SQLiteSession.acquireConnection(SQLiteSession.java:894)
11-01 18:54:51.204: E/AndroidRuntime(28496):    at android.database.sqlite.SQLiteSession.executeForCursorWindow(SQLiteSession.java:834)
11-01 18:54:51.204: E/AndroidRuntime(28496):    at android.database.sqlite.SQLiteQuery.fillWindow(SQLiteQuery.java:62)
11-01 18:54:51.204: E/AndroidRuntime(28496):    at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:143)
11-01 18:54:51.204: E/AndroidRuntime(28496):    at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:133)
11-01 18:54:51.204: E/AndroidRuntime(28496):    at android.database.AbstractCursor.moveToPosition(AbstractCursor.java:196)
11-01 18:54:51.204: E/AndroidRuntime(28496):    at android.database.AbstractCursor.moveToFirst(AbstractCursor.java:236)
11-01 18:54:51.204: E/AndroidRuntime(28496):    at za.example.drawer.Rigstretion$1.onClick(Rigstretion.java:43)
11-01 18:54:51.204: E/AndroidRuntime(28496):    at android.view.View.performClick(View.java:4084)
11-01 18:54:51.204: E/AndroidRuntime(28496):    at android.view.View$PerformClick.run(View.java:16966)
11-01 18:54:51.204: E/AndroidRuntime(28496):    at android.os.Handler.handleCallback(Handler.java:615)
11-01 18:54:51.204: E/AndroidRuntime(28496):    at android.os.Handler.dispatchMessage(Handler.java:92)
11-01 18:54:51.204: E/AndroidRuntime(28496):    at android.os.Looper.loop(Looper.java:137)
11-01 18:54:51.204: E/AndroidRuntime(28496):    at android.app.ActivityThread.main(ActivityThread.java:4745)
11-01 18:54:51.204: E/AndroidRuntime(28496):    at java.lang.reflect.Method.invokeNative(Native Method)
11-01 18:54:51.204: E/AndroidRuntime(28496):    at java.lang.reflect.Method.invoke(Method.java:511)
11-01 18:54:51.204: E/AndroidRuntime(28496):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
11-01 18:54:51.204: E/AndroidRuntime(28496):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-01 18:54:51.204: E/AndroidRuntime(28496):    at dalvik.system.NativeStart.main(Native Method)
11-01 18:54:51.208: W/ActivityManager(325):   Force finishing activity za.example.drawer/.Rigstretion
11-01 18:54:51.256: E/SocketStream(111): readFully was waiting for 275772 bytes, got 49152 
11-01 18:54:51.260: E/SocketStream(111): readFully was waiting for 226620 bytes, got 49152 
11-01 18:54:51.260: E/SocketStream(111): readFully was waiting for 177468 bytes, got 49152 
11-01 18:54:51.264: E/SocketStream(111): readFully was waiting for 128316 bytes, got 16384 
11-01 18:54:51.276: W/audio_hw_primary(114): out_write() limiting sleep time 58911 to 39909
11-01 18:54:51.776: W/ActivityManager(325): Activity pause timeout for ActivityRecord{5355d548 za.example.drawer/.Rigstretion}
11-01 18:55:01.276: W/ActivityManager(325): Launch timeout has expired, giving up wake lock!
11-01 18:55:01.780: W/ActivityManager(325): Activity idle timeout for ActivityRecord{5351228c za.example.drawer/.MainActivity}

所以任何人都可以帮助我???

1 个答案:

答案 0 :(得分:0)

  info.close(); //remove this line
  CR.moveToFirst();

如果我正确理解您的代码,您会遇到异常,因为您尝试在关闭数据库后执行操作。尝试删除info.close();并仅在完成操作后关闭数据库。 (也许在do-while完成之后,在你的情况下)