zoukankan      html  css  js  c++  java
  • SQLite 初步测试

    package org.prothro;
    
    import android.app.Activity;
    import android.database.Cursor;
    import android.database.SQLException;
    import android.database.sqlite.SQLiteDatabase;
    import android.os.Bundle;
    import android.util.Log;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.Toast;
    
    public class SQLiteTestActivity extends Activity {
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            
             final SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(this.getFilesDir().toString() + "/db.db3", null);
             
             Button btn = (Button)findViewById(R.id.button1);
             btn.setOnClickListener(new OnClickListener() {
                final    EditText username = (EditText)findViewById(R.id.username);
                final    EditText password = (EditText)findViewById(R.id.password);
                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
    
                    
                    try{
                        
                        db.execSQL("insert into user values('"+username.getText().toString()+"','"+password.getText().toString()+"')");
                        
                    }catch(SQLException e){
                        e.printStackTrace();
                        db.execSQL(
                                "create table user(username varchar(20),password varchar(20));"
                                );
                        db.execSQL("insert into user values('"+username+"','"+password+"')");
                    }
                    
                    //取出数据库中所有的数据
                    Cursor cursor = db.rawQuery("select * from user", null);
                    
                    while(cursor.moveToNext()){
                        
                        Toast.makeText(
                                SQLiteTestActivity.this, 
                                cursor.getString(cursor.getColumnIndex("username"))+"   "+cursor.getString(cursor.getColumnIndex("password")), 
                                1000).show();
                    }
                    
                }
            });
        }
    }
  • 相关阅读:
    css字体属性相关。
    子级用css float浮动 而父级div没高度不能自适应高度
    转载:基于Redis实现分布式锁
    LeetCode(53):最大子序和
    LeetCode(52):N皇后 II
    LeetCode(51):N皇后
    LeetCode(50):Pow(x, n)
    LeetCode(49): 字母异位词分组
    LeetCode(48):旋转图像
    LeetCode(47):全排列 II
  • 原文地址:https://www.cnblogs.com/laoquans/p/3070682.html
Copyright © 2011-2022 走看看