zoukankan      html  css  js  c++  java
  • 数据库建立

    <?xml version="1.0" encoding="UTF-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:padding="16dp" >
    
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="130dp" >
    
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="姓 名 :"
                android:textSize="18sp" />
    
            <EditText
                android:id="@+id/et_name"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="请输入姓名"
                android:textSize="16sp" />
        </LinearLayout>
    
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="10dp" >
    
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="年 龄:"
                android:textSize="18sp" />
    
            <EditText
                android:id="@+id/et_age"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="输入年龄"
                android:textSize="16sp" />
        </LinearLayout>
    
    
        <Button
            android:id="@+id/btn_add"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/et_age"
            android:layout_marginRight="2dp"
            android:background="#B9B9FF"
            android:onClick="add"
            android:text="注册"
            android:textSize="18sp" />
    
        <TextView
            android:id="@+id/tv_show"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="25dp"
            android:textSize="20sp" />
    
    </LinearLayout>
    package com.example.myapplication;
    
    import androidx.appcompat.app.AppCompatActivity;
    
    import android.database.sqlite.SQLiteDatabase;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.EditText;
    import android.widget.Toast;
    
    public class MainActivity extends AppCompatActivity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
        }
    
        public void add(View v) {
            StuOpenHelper helper = new StuOpenHelper(this);
            SQLiteDatabase db = helper.getWritableDatabase();
            String name = ((EditText) findViewById(R.id.et_name)).getText()
                    .toString();
            int age = Integer.parseInt(((EditText) findViewById(R.id.et_age))
                    .getText().toString());
    
            db.execSQL("insert into stuinfo (name,age) values(?,?)", new Object[]{
                    name, age});
            Toast.makeText(this, "注册成功", Toast.LENGTH_SHORT).show();
    
        }
    }
    package com.example.myapplication;
    
    import android.content.Context;
    import android.database.sqlite.SQLiteDatabase;
    import android.database.sqlite.SQLiteOpenHelper;
    
    
    
    public class StuOpenHelper extends SQLiteOpenHelper {
    
        public StuOpenHelper(Context context) {
            super(context, "student.db", null, 2);
        }
    
        @Override
        public void onCreate(SQLiteDatabase db) {
            db.execSQL("create table stuinfo(_id integer primary key autoincrement,name varchar(20),age integer)");
            db.execSQL("create table class(_id integer primary key autoincrement,classname varchar(20))");
        }
    
        @Override
        public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
            System.out.println("版本更新,老版本是"+ i+"新版本是"+i1);
    
        }
    }
  • 相关阅读:
    设计模式07: Bridge 桥接模式(结构型模式)
    设计模式06: Adapter 适配器模式(结构型模式)
    MySQL性能调优与架构设计——第7章 MySQL数据库锁定机制
    MySQL性能调优与架构设计——第6章 MySQL Server 性能的相关因素
    设计模式05: Prototype 原型模式(创建型模式)
    MySQL性能调优与架构设计——第5章 备份与恢复
    MySQL性能调优与架构设计——第4章 MySQL安全管理
    设计模式04: Factory Methord 工厂方法模式(创建型模式)
    MySQL性能调优与架构设计——第3章 MySQL存储引擎简介
    MySQL性能调优与架构设计——第2章 MySQL架构组成
  • 原文地址:https://www.cnblogs.com/2399301032wr/p/14005192.html
Copyright © 2011-2022 走看看