安卓数据库,某列数据类型是Integer , 怎么从cursor对象中取出来?

图片说明

这两个

图片说明

 Cursor cursor = db.query("AllSense",null,null,
            null, null,null,null);
    int i=cursor.getCount();
 if(i>5){
     cursor.moveToFirst();
   // int  id = cursor.getInt(cursor.getColumnIndex("_id"));
   }

2个回答

直接按照int来取值,Integer是一个类并不是数据基本类型,这里应该表示的意思是id为Integer对象,向数据库存放数值的时候还是int基本类型。

我直接getInt 然后根据列 取不出来呢。int形的就可以。

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
android在数据库中查找相应的数据时出错。
Cursor cursor=myDatabase.rawQuery("select ids,title,times from goodtime" , null); cursor.moveToFirst(); while(!cursor.isAfterLast()){ int id=cursor.getInt(cursor.getColumnIndex("ids")); String title=cursor.getString(cursor.getColumnIndex("title")); String times=cursor.getString(cursor.getColumnIndex("times")); System.out.println(title); System.out.println(cursor.getColumnIndex("bj")); String beijing=cursor.getString(cursor.getColumnIndex("bj")); 上面是我的代码,title还是可以正常查找的,但是bj这个变量的值确实-1,同时报出错误java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.notebook/com.example.notebook.Notebook}: java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it. 这是我创建的表: String ml="create table goodtime(ids integer PRIMARY KEY autoincrement,title text,content text,times text,ptpath text,mppath text,vdpath text,islock integer,password text,bj text)"; arg0.execSQL(ml); 网上说有可能大小写不对,我仔细查看了变量名都是一致的啊 求各位大神帮我看一下,指点一下我,先谢谢了!
在数据库中省略符号和选择数据时程序崩溃
我从 sqlite 数据库中选择数据。问题是当数据库中有省略符号,比如 " I' m John " ,当我选择数据时,程序就崩溃。 当程序中没有省略符号,一切都运行正常。 选择数据的函数: String query = "SELECT * FROM " + mainCollumn + " WHERE used=0 " + " AND season <= " + seasons + " ORDER BY RANDOM() LIMIT " + count ; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(query, null); if(cursor.moveToFirst()){ do { Question question = new Question(Integer.parseInt(cursor.getString(0)), cursor.getString(1),cursor.getString(2),cursor.getString(3),cursor.getString(4),cursor.getString(5), Integer.parseInt(cursor.getString(6))); questionList.add(question); }while(cursor.moveToNext()); }
这个利用sqlite写的数据库为什么退出应用后再进去数据库就无法找到了啊
package com.sample.Sample_8_4; import android.app.Activity; import android.app.AlertDialog; import android.content.ContentValues; import android.content.DialogInterface; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.Toast; public class Sample_8_4 extends Activity { private Button baseButton; private Button tableButton; private Button btn_sqlmod, btn_cvmod, btn_qur; private final String dbName = "mydb"; private final String tableName = "users"; private SQLiteDatabase db = null; private int i = 1; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.setContentView(R.layout.main); baseButton = (Button) findViewById(R.id.base); // 实例化Button对象 baseButton.setOnClickListener(new OnClickListener() { // 为Button对象添加监听 public void onClick(View v) { db = openOrCreateDatabase(dbName, MODE_PRIVATE, null); // 创建名为“mydb”的数据库 db.endTransaction(); Toast.makeText(getApplicationContext(), "创建数据库成功", 1000) .show(); } }); tableButton = (Button) findViewById(R.id.table); // 实例化Button对象 tableButton.setOnClickListener(new OnClickListener() { // 为Button对象添加监听 public void onClick(View v) { if (db != null) { creatTable(); // 开始创建数据库表 } else { Toast.makeText(getApplicationContext(), "没有数据库", 1000).show(); } } }); btn_sqlmod = (Button) findViewById(R.id.sql_mod); btn_sqlmod.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub if (db != null) { sql_executeData(); } else { Toast.makeText(getApplicationContext(), "没有数据库", 1000) .show(); } } }); btn_cvmod = (Button) findViewById(R.id.cv_mod); btn_cvmod.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub if (db != null) { cv_executeData(); } else { Toast.makeText(getApplicationContext(), "没有数据库", 1000) .show(); } } }); btn_qur = (Button) findViewById(R.id.que); btn_qur.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub if (db != null) { queryData(); } else { Toast.makeText(getApplicationContext(), "没有数据库", 1000) .show(); } } }); } public void creatTable() { // 创建表的SQL语句,创建一个名为users的表,该表有id,uname和pwd三个字段 String sql = "CREATE TABLE IF NOT EXISTS " + tableName + " (id INTEGER PRIMARY KEY AUTOINCREMENT, uname VARCHAR(50), pwd VARCHAR(50));"; db.execSQL(sql); // 执行sql语句 db.endTransaction(); // 查询sqlite_master表中类型为table的记录的name字段 Cursor cursor = db.query("sqlite_master", new String[] { "name" }, "type = ?", new String[] { "table" }, null, null, null, null); String tables = ""; if (cursor.getCount() != 0) { // 判断查询结果的条数是否为0 cursor.moveToFirst(); // 游标指向第一条记录 for (int i = 0; i < cursor.getCount(); i += 1) { tables = tables + cursor.getString(0) + " "; // 累加字符串 cursor.moveToNext(); // 游标下移 } } // 把累加的结果显示在一个信息框中 new AlertDialog.Builder(Sample_8_4.this).setTitle("Message") .setMessage(tables) .setNegativeButton("确定", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { } }).show(); } public void sql_executeData() { String sql; for (; i < 4; i++) { sql = "insert into " + tableName + " values ('" + i + "','a','123456')"; // 添加一条记录 db.execSQL(sql); db.endTransaction(); } sql = "update " + tableName + " set pwd='654321' where id='1'"; // 修改一条记录 db.execSQL(sql); db.endTransaction(); sql = "delete from " + tableName + " where id='2'"; // 删除一条记录 db.execSQL(sql); db.endTransaction(); Toast.makeText(getApplicationContext(), "使用SQL语句修改数据成功", 1000).show(); } public void cv_executeData() { ContentValues cv = new ContentValues(); // 实例化ContentValues对象 cv.put("uname", "b"); // 插入字段值 cv.put("pwd", "987654"); // 插入字段值 db.insert(tableName, null, cv); // 执行insert方法 db.insert(tableName, null, cv); // 执行insert方法 db.insert(tableName, null, cv); // 执行insert方法 cv = new ContentValues(); // 实例化ContentValues对象 cv.put("pwd", "456789"); // 插入字段值 db.update(tableName, cv, "id=?", new String[] { "4" }); // 执行update方法 db.delete(tableName, "id=?", new String[] { "5" }); // 执行delete操作 Toast.makeText(getApplicationContext(), "使用Android语句修改数据成功", 1000) .show(); } public void queryData() { Cursor cursor = db.query(tableName, null, null, null, null, null, null, null); // 执行query操作获得Cursor对象 String str = ""; if (cursor.getCount() != 0) { // 判断返回的记录条数 cursor.moveToFirst(); // 游标指向第一条记录 for (int i = 0; i < cursor.getCount(); i += 1) { str = str + cursor.getString(0) + " " + cursor.getString(1) + " " + cursor.getString(2) + "\n"; // 获取一条记录的每个字段的值 cursor.moveToNext(); // 游标指向下一条记录 } } // 在信息框上显示所有记录信息 new AlertDialog.Builder(Sample_8_4.this).setTitle("Message") .setMessage(str) .setNegativeButton("确定", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { } }).show(); } }
android studiod 从数据库读取数据失败
从数据库读取数据到listview,但是不知为什么,在没添加数据进数据库的时候,能进activity,但是一旦添加进去以后就开始报错了 DBhelper.java public class DBHelper extends SQLiteOpenHelper{ private final static String DATABASE_NAME = "demo.db"; private final static int DATABASE_VERSION = 1; private final static String TABLE_NAME = "request_list"; public final static String REQUEST_ID = "request_id"; public final static String REPORTER_NAME = "reporter_name"; public final static String S_DESCRIPTION = "s_description"; public final static String L_DESCRIPTION = "l_description"; public final static String DEPARTMENT = "department"; public final static String CATEGORY = "category"; public DBHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); Log.e("Database operations", "Database created/opened"); } @Override public void onCreate(SQLiteDatabase db) { String sql = "CREATE TABLE " + TABLE_NAME + " (" + REQUEST_ID + " INTEGER primary key autoincrement, " + "" + REPORTER_NAME + " text, " + "" + S_DESCRIPTION + " text, " + "" + L_DESCRIPTION + " text, " + "" + DEPARTMENT + " text, " + "" + CATEGORY + " text);"; db.execSQL(sql); Log.e("Database operations", "Table created/opened"); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { String sql = "DROP TABLE IF EXISTS " + TABLE_NAME; db.execSQL(sql); onCreate(db); } public Cursor select() { SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db .query(TABLE_NAME, null, null, null, null, null, null); return cursor; } public Cursor getInformation(SQLiteDatabase db) { Cursor cursor; String[] projection = {REPORTER_NAME,S_DESCRIPTION,L_DESCRIPTION,DEPARTMENT,CATEGORY}; cursor=db.query(TABLE_NAME,projection,null,null,null,null,null,null); return cursor; } //增加操作 public long insert(String s_description,String name,String department, String category,String l_description) { SQLiteDatabase db = this.getWritableDatabase(); /* ContentValues */ ContentValues cv = new ContentValues(); cv.put(S_DESCRIPTION, s_description); cv.put(L_DESCRIPTION,l_description); cv.put(REPORTER_NAME,name); cv.put(DEPARTMENT,department); cv.put(CATEGORY,category); long row = db.insert(TABLE_NAME, null, cv); return row; } //删除操作 public void delete(int id) { SQLiteDatabase db = this.getWritableDatabase(); String where = REQUEST_ID + " = ?"; String[] whereValue ={ Integer.toString(id) }; db.delete(TABLE_NAME, where, whereValue); } //修改操作 public void update(int id, String s_description,String name,String department, String category,String l_description) { SQLiteDatabase db = this.getWritableDatabase(); String where = REQUEST_ID + " = ?"; String[] whereValue = { Integer.toString(id) }; ContentValues cv = new ContentValues(); cv.put(S_DESCRIPTION, s_description); cv.put(L_DESCRIPTION,l_description); cv.put(REPORTER_NAME,name); cv.put(DEPARTMENT,department); cv.put(CATEGORY,category); db.update(TABLE_NAME, cv, where, whereValue); } } DataListActivity.java public class DataListActivity extends ActionBarActivity { ListView listView; SQLiteDatabase sqLiteDatabase; DBHelper dbHelper; Cursor cursor; ListDataAdapter listDataAdapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.data_list_layout); listView = (ListView) findViewById(R.id.list_view); listDataAdapter = new ListDataAdapter(getApplicationContext(),R.layout.reporter_my_request); listView.setAdapter(listDataAdapter); dbHelper = new DBHelper(getApplicationContext()); sqLiteDatabase = dbHelper.getReadableDatabase(); cursor = dbHelper.getInformation(sqLiteDatabase); if(cursor.moveToFirst()) { do { String name,title,department,category,description; name = cursor.getString(0); title= cursor.getString(1); department=cursor.getString(2); category=cursor.getString(3); description=cursor.getString(4); DataProvider dataProvider=new DataProvider(name,title,department,category,description); listDataAdapter.add(dataProvider); }while (cursor.moveToNext()); } dbHelper.close(); } } DataProvider.java public class DataProvider { private String name; private String title; private String department; private String category; private String description; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getDepartment() { return department; } public void setDepartment(String department) { this.department = department; } public String getCategory() { return category; } public void setCategory(String category) { this.category = category; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public DataProvider(String name,String title,String department,String category,String description){ this.name= name; this.title = title; this.department= department; this.category= category; this.description = description; } } ListDataAdapter.java public class ListDataAdapter extends ArrayAdapter { List list = new ArrayList(); public ListDataAdapter(Context context, int resource) { super(context, resource); } static class LayoutHandler{ TextView NAME,TITLE,DEPARTMENT,CATEGORY,DESCRIPTION; } @Override public void add(Object object) { super.add(object); list.add(object); } @Override public int getCount() { return list.size(); } @Override public Object getItem(int position) { return list.get(position); } @Override public View getView(int position, View convertView, ViewGroup parent) { View row = convertView; LayoutHandler layoutHandler; if(row == null){ LayoutInflater layoutInflater = (LayoutInflater)this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); row = layoutInflater.inflate(R.layout.reporter_my_request,parent,false); layoutHandler = new LayoutHandler(); layoutHandler.NAME = (TextView)row.findViewById(R.id.text_name); layoutHandler.TITLE = (TextView)row.findViewById(R.id.text_title); layoutHandler.DEPARTMENT = (TextView)row.findViewById(R.id.text_department); layoutHandler.CATEGORY = (TextView)row.findViewById(R.id.text_category); row.setTag(layoutHandler); } else { layoutHandler = (LayoutHandler)row.getTag(); } DataProvider dataProvider = (DataProvider)this.getItem(position); layoutHandler.NAME.setText(dataProvider.getName()); layoutHandler.TITLE.setText(dataProvider.getTitle()); layoutHandler.DEPARTMENT.setText(dataProvider.getDepartment()); layoutHandler.CATEGORY.setText(dataProvider.getCategory()); layoutHandler.DESCRIPTION.setText(dataProvider.getDescription()); return row; } }
SQLite在查询数据库运行崩溃
这是我创建的数据库 public class BlackNumberOpenHelper extends SQLiteOpenHelper { private static final String TAG = "BlackNumberOpenHelper"; /** * @param context */ public BlackNumberOpenHelper(Context context) { super(context, "blacknumber.db", null, 1); } @Override public void onCreate(SQLiteDatabase db) { db.execSQL("create table blacknumber (_id integer primary key autoincrement,number varchar(20),mode varchar(2))"); Log.i(TAG,"成功创建表"); }} 以下是我操作数据库的类 public class BlackNumberDao { private Context context; private BlackNumberOpenHelper helper; /** * 构造方法 * @param context */ public BlackNumberDao(Context context) { this.context = context; helper = new BlackNumberOpenHelper(context); } public List<BlackNumberInfo> findAll() { List<BlackNumberInfo> result = new ArrayList<BlackNumberInfo>(); SQLiteDatabase db = helper.getWritableDatabase(); Cursor cursor = db.query("blacknumber",new String[]{"number","mode"},null,null,null,null,null); while (cursor.moveToNext()) { BlackNumberInfo info = new BlackNumberInfo(); String number = cursor.getString(0); String mode = cursor.getString(1); info.setMode(mode); info.setNumber(number); result.add(info); } cursor.close(); db.close(); return result; }} 为什么一执行查询全部的操作就报android.database.sqlite.SQLiteException: no such table: blacknumber (code 1): , while compiling: SELECT number, mode FROM blacknumber。希望大家帮我看看到底我哪里错了啊。首先先谢谢大家了
我想把SQLite数据库里的数据显示到ListView上,代码有什么问题吗?
private ListView listview = null; private List<Map<String, Object>> list = new ArrayList<Map<String, Object>>(); private SimpleAdapter simpleAdapter = null; private ImageView iv; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //适配器添加查询结果,并加到ListView中显示 simpleAdapter = new SimpleAdapter(this, getData(), R.layout.item, new String[] {"name", "waimao","time","contact" ,"image"}, new int[] { R.id.name, R.id.waimao,R.id.time,R.id.contact,R.id.imageView1 }); listview.setAdapter(simpleAdapter); } /** * * @return */ private List<Map<String, Object>> getData() { DBHelper dbHelper = new DBHelper(this); SQLiteDatabase db = dbHelper.getReadableDatabase(); Cursor cursor = db.rawQuery("select * from post", null); while (cursor.moveToNext()) { Integer pid = cursor.getInt(cursor.getColumnIndex("id")); String pname = cursor.getString(cursor.getColumnIndex("name")); String waimao = cursor.getString(cursor.getColumnIndex("waimao")); String time=cursor.getString(cursor.getColumnIndex("time")); String contact=cursor.getString(cursor.getColumnIndex("contact")); //从数据库中提取图片 byte[] pimage=null; pimage=cursor.getBlob(cursor.getColumnIndex("image")); Bitmap imagebitmap=BitmapFactory.decodeByteArray(pimage, 0, pimage.length); iv=(ImageView)findViewById(R.id.imageView1); iv.setImageBitmap(imagebitmap); //这里同样是查询,只不过把查询到的数据添加到list集合,可以参照ListView的用法 Map<String, Object> map = new HashMap<String, Object>(); map.put("id", pid); //获取_id map.put("name", pname); //获取name map.put("waimao", waimao); map.put("time", time); map.put("contact", contact); map.put("image",imagebitmap); list.add(map); } return list; }
安卓,创建数据库时崩溃了
DatabaseHelper.java ``` package com.exampl.mysql; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase.CursorFactory; import android.database.sqlite.SQLiteOpenHelper; import android.widget.Toast; public class DatabaseHelper extends SQLiteOpenHelper{ private Context mContext; public static final String CREATE_TABLE_SQL="create table dict(_id integer primary key autoincrement,word text,detail text);"; public DatabaseHelper(Context context,String name,CursorFactory factory,int version) { super(context,name,factory,version); mContext=context; } public void onCreate(SQLiteDatabase db) { db.execSQL(CREATE_TABLE_SQL); Toast.makeText(mContext,"创建成功!",Toast.LENGTH_LONG).show(); } public void onUpgrade(SQLiteDatabase db,int oldVersion,int newVersion) { } } ``` MainActivity.java ``` package com.exampl.mysql; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; import android.app.Activity; import android.content.Intent; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; public class MainActivity extends Activity implements OnClickListener{ private Button insert=null; private Button search=null; private EditText word=null; private EditText detail=null; private EditText key=null; DatabaseHelper dbHelper; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); dbHelper=new DatabaseHelper(this,"myDict.db3",null,1); insert=(Button)findViewById(R.id.insert); insert.setOnClickListener(this); search=(Button)findViewById(R.id.search); search.setOnClickListener(this); word=(EditText)findViewById(R.id.word); detail=(EditText)findViewById(R.id.detail); key=(EditText)findViewById(R.id.key); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.insert: String wor=word.getText().toString().trim(); String det=detail.getText().toString().trim(); insertData(dbHelper.getReadableDatabase(),wor,det); Toast.makeText(this, "添加生词成功!", Toast.LENGTH_LONG).show(); break; case R.id.search: String ke=key.getText().toString().trim(); Cursor cursor=dbHelper.getReadableDatabase().rawQuery("select*from dict where word like? or details like?", new String[]{"%"+ke+"%","%"+ke+"%"}); Bundle data=new Bundle(); data.putSerializable("date", converCursorToList(cursor)); Intent intent=new Intent(MainActivity.this,Result.class); intent.putExtras(data); startActivity(intent); break; default:break; } } protected ArrayList<Map<String,String>> converCursorToList(Cursor cursor) { ArrayList<Map<String,String>> result=new ArrayList<Map<String,String>>(); while (cursor.moveToNext()) { Map<String,String> map=new HashMap<String,String>(); map.put("word", cursor.getString(1)); map.put("detail", cursor.getString(2)); result.add(map); } return result; } private void insertData(SQLiteDatabase db,String word,String detail) { db.execSQL("insert into dict values(null,?,?)"+new String[]{word,detail}); } @Override public void onDestroy() { super.onDestroy(); if (dbHelper!=null) dbHelper.close(); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } } ``` Result.java ``` package com.exampl.mysql; import android.app.Activity; import android.os.Bundle; import android.widget.TextView; public class Result extends Activity { private TextView jieguo=null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.line); jieguo=(TextView)findViewById(R.id.jieguo); Bundle bundle=getIntent().getExtras(); jieguo.setText(bundle.getString("date")); } } ``` ![图片说明](https://img-ask.csdn.net/upload/201612/15/1481764101_229239.jpg) ![图片说明](https://img-ask.csdn.net/upload/201612/15/1481764114_286139.png) ![图片说明](https://img-ask.csdn.net/upload/201612/15/1481764138_253207.jpg)
如何删除数据库中的数据?
当我点击列表视图中的一个选项时,如何删除数据库中的数据?我使用下面的方法来选择列表视图的选项。 listview.setOnItemClickListener(new OnItemClickListener(){ public void onItemClick(AdapterView adapterView, View convertView, int position, long id) { AlertDialog.Builder alertDialog = new AlertDialog.Builder(AndroidSpinnerFromSQLiteActivity.this); alertDialog.setTitle("Confirm Delete..."); alertDialog.setMessage("Are you sure you want delete this?"); alertDialog.setIcon(R.drawable.delete); alertDialog.setPositiveButton("YES", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog,int which) { } }); alertDialog.setNegativeButton("NO", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { } }); alertDialog.show(); } }); }; 数据库类: public class DatabaseHandler extends SQLiteOpenHelper { private static final int DATABASE_VERSION = 1; private static final String DATABASE_NAME = "spinnerExample"; private static final String TABLE_LABELS = "labels"; private static final String KEY_ID = "id"; private static final String KEY_NAME = "name"; public DatabaseHandler(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); } @Override public void onCreate(SQLiteDatabase db) { String CREATE_CATEGORIES_TABLE = "CREATE TABLE " + TABLE_LABELS + "(" + KEY_ID + " INTEGER PRIMARY KEY," + KEY_NAME + " TEXT" +")"; db.execSQL(CREATE_CATEGORIES_TABLE); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { db.execSQL("DROP TABLE IF EXISTS " + TABLE_LABELS); onCreate(db); } public void insertLabel(String label){ SQLiteDatabase db = this.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(KEY_NAME, label); db.insert(TABLE_LABELS, null, values); db.close(); } public List<String> getAllLabels(){ List<String> labels = new ArrayList<String>(); String selectQuery = "SELECT * FROM " + TABLE_LABELS; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } cursor.close(); db.close(); return labels; } }
Android中SQLite数据库查询不到的问题,求大神帮忙
private static String sql1="create table user( _id integer primary key autoincrement, name varchar(20), pwd varchar(20))"; private static String sql2="create table account_book("+ "_id integer primary key autoincrement,"+ "name varchar(20) not null,"+ "user_id references user(_id) not null,"+ "cash double ,"+ " disposit_card double,"+ " credit_card double,"+ "alipay double )"; private static String sql3= " create table payin("+ " _id integer primary key autoincrement,"+ "account_id references account_book(_id) not null,"+ "type varchar(20),"+ "use varchar(20),"+ "date,"+ "count integer(20),"+ "qianbao varchar(20),"+ "beizhu varchar(30) )"; public void onCreate(SQLiteDatabase db) { // TODO Auto-generated method stub db.execSQL(sql1); db.execSQL(sql2); db.execSQL(sql3); } 以上是建表语句。 以下根据user_id 在account_book表中查询时返回的cursor中没有记录getcount=0 根据account_id在payin表中查询也是一样的情况。 下面是我的查询语句: Cursor cursor=database.query("account_book",new String[]{"_id"},"user_id=?", new String[]{user_id+""}, null, null, null); Cursor cursor=database.query("payin",new String[]{"_id","type","use","count","qianbao","beizhu"}, "account_id=?and type=?", new String[]{account_id.toString(),type}, null, null, "_id"); 请大神解惑,拜托了
如何在Sqlite数据库中插入数据列表?
我创建了一个简单的数据库用来插入数据库列表,但是当我想把数据发送到数据库时,有下面的错误: 08-28 15:30:43.015: ERROR/Database(822): Failure 1 (no such column: Sharma) on 0x276e50 when preparing 'INSERT INTO friends Values(Sharma,SaiGeetha,18);"" 相关的代码: sampleDB = this.openOrCreateDatabase(SAMPLE_DB_NAME, MODE_PRIVATE, null); ArrayList<String>FirstName = new ArrayList<String>(); ArrayList<String>LastName = new ArrayList<String>(); ArrayList<Integer >Age = new ArrayList<Integer>(); FirstName.add("SaiGeetha"); FirstName.add("Vivek"); FirstName.add("Rahul"); LastName.add("Sharma"); LastName.add("Lilani"); LastName.add("Lami"); Age.add(18); Age.add(20); Age.add(23); sampleDB.execSQL("CREATE TABLE IF NOT EXISTS " + SAMPLE_TABLE_NAME + " (LastName VARCHAR, FirstName VARCHAR," + " Age INT(3));"); for(int i=0;i<3;i++) { sampleDB.execSQL("INSERT INTO " + enter code here SAMPLE_TABLE_NAME + " Values("+LastName.get(i)+","+FirstName.get(i)+","+Age.get(i)+");"+"\"\""); } /*sampleDB.execSQL("INSERT INTO " + SAMPLE_TABLE_NAME + " Values ('Makam','Sai Geetha','India',25);"); sampleDB.execSQL("INSERT INTO " + SAMPLE_TABLE_NAME + " Values ('Chittur','Raman','India',25);"); sampleDB.execSQL("INSERT INTO " + SAMPLE_TABLE_NAME + " Values ('Solutions','Collabera','India',20);");*/ Cursor c = sampleDB.rawQuery("SELECT FirstName, Age FROM " + SAMPLE_TABLE_NAME + " where Age > 10 LIMIT 5", null); if (c != null ) { if (c.moveToFirst()) { do { String firstName = c.getString(c.getColumnIndex("FirstName")); int age = c.getInt(c.getColumnIndex("Age")); Log.e("---LIST FROM DATABASE--","---VALUE---"+firstName); Log.e("---LIST FROM DATABASE--","---VALUE---"+age ); }while (c.moveToNext()); } } sampleDB.close(); } catch (SQLiteException se ) { Log.e(getClass().getSimpleName(), "Could not create or Open the database"); } finally { if (sampleDB != null) sampleDB.execSQL("DELETE FROM " + SAMPLE_TABLE_NAME); sampleDB.close(); } } 哪里的问题呢?
关于 安卓数据库查询问题 怎样将查询到的信息存入数组 再用bundler传递
灌水 无聊的别来 别搞事情 我就想花C找人帮忙解决问题 丢一句话的你就别发了 没有代码 你也别发了 多看下我的问题描述 你有好的方法也可以贴代码给我看 我想说一下我写的东西的功能 就是在一个有很多imagebutton的页面 点击一个imagebtn 通过Switch 选择后 在新的页面输出对应的 图片 和 文字描述 。文字的描述是通过数据库查找出来的! 我现在已经实现了图片传递 ,但是文字查询传递我还没有实现 我的想法是 定义一个方法 public String query(int i){ Cursor cursor = db.rawQuery("select content from car "); 然后定义一个数组 将cursor查询到的内容存入数组 再通过query( int i )给的i找到数组对应的内容 最后return } 如果是我的想法 有问题 希望大佬能告诉下这个该用什么方法解决 顺便写一下方法代码 全部代码 MainActivity.java public class MainActivity extends AppCompatActivity { private ImageButton ib0; private MyOpenHelper myOpenHelper; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); this.myOpenHelper = new MyOpenHelper(this); myOpenHelper.getWritableDatabase(); ib0 = (ImageButton)findViewById(R.id.ib0); ib0.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View view) { Intent i0 = new Intent(MainActivity.this,Main2Activity.class); startActivity(i0); } }); } } Main2Activity.java public class Main2Activity extends Activity implements View.OnClickListener { private ImageButton ib1,ib2,ib3,ib4,ib5,ib6,ib7,ib8,ib9,ib10,ib11,ib12; private SQLiteDatabase db; private Cursor cursor; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main2); ib1 = findViewById(R.id.ib1); ib2 = findViewById(R.id.ib2); ib3 = findViewById(R.id.ib3); ib4 = findViewById(R.id.ib4); ib5 = findViewById(R.id.ib5); ib6 = findViewById(R.id.ib6); ib7 = findViewById(R.id.ib7); ib8 = findViewById(R.id.ib8); ib9 = findViewById(R.id.ib9); ib10 = findViewById(R.id.ib10); ib11 = findViewById(R.id.ib11); ib12 = findViewById(R.id.ib12); ib1.setOnClickListener(this); ib2.setOnClickListener(this); ib3.setOnClickListener(this); ib4.setOnClickListener(this); ib5.setOnClickListener(this); ib6.setOnClickListener(this); ib7.setOnClickListener(this); ib8.setOnClickListener(this); ib9.setOnClickListener(this); ib10.setOnClickListener(this); ib11.setOnClickListener(this); ib12.setOnClickListener(this); } @Override public void onClick(View view) { switch (view.getId()){ case R.id.ib1: Intent i1 = new Intent(Main2Activity.this,Main3Activity.class); Bundle bundle1 = new Bundle(); bundle1.putInt("imagebtn",R.mipmap.a); // bundle1.putString("text",query(0)); i1.putExtras(bundle1); startActivity(i1); break; case R.id.ib2: Intent i2 = new Intent(Main2Activity.this,Main3Activity.class); Bundle bundle2 = new Bundle(); bundle2.putInt("imagebtn",R.mipmap.b); i2.putExtras(bundle2); startActivity(i2); break; case R.id.ib3: Intent i3 = new Intent(Main2Activity.this,Main3Activity.class); Bundle bundle3 = new Bundle(); bundle3.putInt("imagebtn",R.mipmap.c); i3.putExtras(bundle3); startActivity(i3); break; case R.id.ib4: Intent i4 = new Intent(Main2Activity.this,Main3Activity.class); Bundle bundle4 = new Bundle(); bundle4.putInt("imagebtn",R.mipmap.d); i4.putExtras(bundle4); startActivity(i4); break; case R.id.ib5: Intent i5 = new Intent(Main2Activity.this,Main3Activity.class); Bundle bundle5 = new Bundle(); bundle5.putInt("imagebtn",R.mipmap.e); i5.putExtras(bundle5); startActivity(i5); break; case R.id.ib6: Intent i6 = new Intent(Main2Activity.this,Main3Activity.class); Bundle bundle6 = new Bundle(); bundle6.putInt("imagebtn",R.mipmap.f); i6.putExtras(bundle6); startActivity(i6); break; case R.id.ib7: Intent i7 = new Intent(Main2Activity.this,Main3Activity.class); Bundle bundle7 = new Bundle(); bundle7.putInt("imagebtn",R.mipmap.g); i7.putExtras(bundle7); startActivity(i7); break; case R.id.ib8: Intent i8 = new Intent(Main2Activity.this,Main3Activity.class); Bundle bundle8 = new Bundle(); bundle8.putInt("imagebtn",R.mipmap.h); i8.putExtras(bundle8); startActivity(i8); break; case R.id.ib9: Intent i9 = new Intent(Main2Activity.this,Main3Activity.class); Bundle bundle9 = new Bundle(); bundle9.putInt("imagebtn",R.mipmap.i); i9.putExtras(bundle9); startActivity(i9); break; case R.id.ib10: Intent i10 = new Intent(Main2Activity.this,Main3Activity.class); Bundle bundle10 = new Bundle(); bundle10.putInt("imagebtn",R.mipmap.j); i10.putExtras(bundle10); startActivity(i10); break; case R.id.ib11: Intent i11 = new Intent(Main2Activity.this,Main3Activity.class); Bundle bundle11 = new Bundle(); bundle11.putInt("imagebtn",R.mipmap.k); i11.putExtras(bundle11); startActivity(i11); break; case R.id.ib12: Intent i12 = new Intent(Main2Activity.this,Main3Activity.class); Bundle bundle12 = new Bundle(); bundle12.putInt("imagebtn",R.mipmap.l); i12.putExtras(bundle12); startActivity(i12); break; } } Main3Activity.java public class Main3Activity extends AppCompatActivity { private ImageView imageView; private TextView textView; private int i1; private String i2; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main3); imageView = (ImageView) findViewById(R.id.iv); textView = (TextView)findViewById(R.id.textv) ; Intent intent = getIntent(); if (intent != null) { Bundle bundle = intent.getExtras(); i1 = bundle.getInt("imagebtn"); i2 = bundle.getString("text"); } imageView.setImageResource(i1); textView.setText(i2); } } public class MyOpenHelper extends SQLiteOpenHelper { public MyOpenHelper(Context context){ super(context,"car.db",null,1); } @Override public void onCreate(SQLiteDatabase db) { db.execSQL("create table [user] ([id] integer not null primary key autoincrement,[name] varchar(255) not null,[content] varchar(255) not null)"); } @Override public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) { } }
使用 Sqiltehelper 如何删除表格和数据库
我创建了一个类调用 DatabaseHandler 继承SQLiteOpenHelper。我想删除数据库或者在点击按钮时删除表格,如何处理那些我调用方法而传递的参数? 供参考的代码: public class DatabaseHandler extends SQLiteOpenHelper { // All Static variables // Database Version public static final int DATABASE_VERSION =1; // Database Name public static final String DATABASE_NAME = "EmployeeDB"; // Contacts table name public static final String TABLE_CONTACTS = "contacts"; // Contacts Table Columns names private static final String KEY_ID = "id"; private static final String KEY_NAME = "name"; private static final String KEY_PH_NO = "phone_number"; public DatabaseHandler(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); } @Override public void onCreate(SQLiteDatabase db) { // TODO Auto-generated method stub String CREATE_CONTACTS_TABLE = "CREATE TABLE " + TABLE_CONTACTS + "(" + KEY_ID + " INTEGER PRIMARY KEY," + KEY_NAME + " TEXT," + KEY_PH_NO + " TEXT" + ")"; db.execSQL(CREATE_CONTACTS_TABLE); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { // TODO Auto-generated method stub db.execSQL("DROP TABLE IF EXISTS " + TABLE_CONTACTS); // Create tables again onCreate(db); } /** * All CRUD(Create, Read, Update, Delete) Operations */ // Adding new contact void addContact(Contact contact) { SQLiteDatabase db = this.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(KEY_NAME, contact.getName()); // Contact Name values.put(KEY_PH_NO, contact.getPhoneNumber()); // Contact Phone // Inserting Row db.insert(TABLE_CONTACTS, null, values); db.close(); // Closing database connection } // Getting single contact Contact getContact(int id) { SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.query(TABLE_CONTACTS, new String[] { KEY_ID, KEY_NAME, KEY_PH_NO }, KEY_ID + "=?", new String[] { String.valueOf(id) }, null, null, null, null); if (cursor != null) cursor.moveToFirst(); Contact contact = new Contact(id, cursor.getString(1), cursor.getString(2)); // return contact return contact; } // Getting All Contacts public List<Contact> getAllContacts() { List<Contact> contactList = new ArrayList<Contact>(); // Select All Query String selectQuery = "SELECT * FROM " + TABLE_CONTACTS; SQLiteDatabase db = this.getWritableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); // looping through all rows and adding to list if (cursor.moveToFirst()) { do { Contact contact = new Contact(); contact.setID(Integer.parseInt(cursor.getString(0))); contact.setName(cursor.getString(1)); contact.setPhoneNumber(cursor.getString(2)); // Adding contact to list contactList.add(contact); } while (cursor.moveToNext()); } // return contact list return contactList; } // Updating single contact public int updateContact(Contact contact) { SQLiteDatabase db = this.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(KEY_NAME, contact.getName()); values.put(KEY_PH_NO, contact.getPhoneNumber()); // updating row return db.update(TABLE_CONTACTS, values, KEY_ID + " = ?", new String[] { String.valueOf(contact.getID()) }); } // Deleting single contact public void deleteContact(Contact contact) { SQLiteDatabase db = this.getWritableDatabase(); db.delete(TABLE_CONTACTS, KEY_ID + " = ?", new String[] { String.valueOf(contact.getID()) }); db.close(); } // Getting contacts Count public int getContactsCount() { String countQuery = "SELECT * FROM " + TABLE_CONTACTS; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(countQuery, null); cursor.close(); // return count return cursor.getCount(); } public void DeleteDatabase(SQLiteDatabase db,String table) { db.execSQL("DELETE FROM " + table); db.close(); }
使用 Sqiltehelper 如何删除表格和数据库?
我创建了一个类名称是 DatabaseHandler,继承 SQLiteOpenHelper。我想通过按钮点击删除数据库或表格。如何处理调用函数时传递的参数? public class DatabaseHandler extends SQLiteOpenHelper { // All Static variables // Database Version public static final int DATABASE_VERSION =1; // Database Name public static final String DATABASE_NAME = "EmployeeDB"; // Contacts table name public static final String TABLE_CONTACTS = "contacts"; // Contacts Table Columns names private static final String KEY_ID = "id"; private static final String KEY_NAME = "name"; private static final String KEY_PH_NO = "phone_number"; public DatabaseHandler(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); } @Override public void onCreate(SQLiteDatabase db) { // TODO Auto-generated method stub String CREATE_CONTACTS_TABLE = "CREATE TABLE " + TABLE_CONTACTS + "(" + KEY_ID + " INTEGER PRIMARY KEY," + KEY_NAME + " TEXT," + KEY_PH_NO + " TEXT" + ")"; db.execSQL(CREATE_CONTACTS_TABLE); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { // TODO Auto-generated method stub db.execSQL("DROP TABLE IF EXISTS " + TABLE_CONTACTS); // Create tables again onCreate(db); } // Adding new contact void addContact(Contact contact) { SQLiteDatabase db = this.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(KEY_NAME, contact.getName()); // Contact Name values.put(KEY_PH_NO, contact.getPhoneNumber()); // Contact Phone // Inserting Row db.insert(TABLE_CONTACTS, null, values); db.close(); // Closing database connection } // Getting single contact Contact getContact(int id) { SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.query(TABLE_CONTACTS, new String[] { KEY_ID, KEY_NAME, KEY_PH_NO }, KEY_ID + "=?", new String[] { String.valueOf(id) }, null, null, null, null); if (cursor != null) cursor.moveToFirst(); Contact contact = new Contact(id, cursor.getString(1), cursor.getString(2)); // return contact return contact; } // Getting All Contacts public List<Contact> getAllContacts() { List<Contact> contactList = new ArrayList<Contact>(); // Select All Query String selectQuery = "SELECT * FROM " + TABLE_CONTACTS; SQLiteDatabase db = this.getWritableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); // looping through all rows and adding to list if (cursor.moveToFirst()) { do { Contact contact = new Contact(); contact.setID(Integer.parseInt(cursor.getString(0))); contact.setName(cursor.getString(1)); contact.setPhoneNumber(cursor.getString(2)); // Adding contact to list contactList.add(contact); } while (cursor.moveToNext()); } // return contact list return contactList; } // Updating single contact public int updateContact(Contact contact) { SQLiteDatabase db = this.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(KEY_NAME, contact.getName()); values.put(KEY_PH_NO, contact.getPhoneNumber()); // updating row return db.update(TABLE_CONTACTS, values, KEY_ID + " = ?", new String[] { String.valueOf(contact.getID()) }); } // Deleting single contact public void deleteContact(Contact contact) { SQLiteDatabase db = this.getWritableDatabase(); db.delete(TABLE_CONTACTS, KEY_ID + " = ?", new String[] { String.valueOf(contact.getID()) }); db.close(); } // Getting contacts Count public int getContactsCount() { String countQuery = "SELECT * FROM " + TABLE_CONTACTS; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(countQuery, null); cursor.close(); // return count return cursor.getCount(); } public void DeleteDatabase(SQLiteDatabase db,String table) { db.execSQL("DELETE FROM " + table); db.close(); }
安卓,查询数据时怎么什么也没有查到?
数据库创建成功了,添加数据也成功了。但在查询数据跳转到第二个Activity时是白屏, 什么也没查到,调试的结果是没有进入到while里面去执行,为什么没满足while条件, 怎么改? ![图片说明](https://img-ask.csdn.net/upload/201612/16/1481840102_551791.png) ![图片说明](https://img-ask.csdn.net/upload/201612/16/1481840116_963276.png) ![图片说明](https://img-ask.csdn.net/upload/201612/16/1481840132_440910.jpg) DatabaseHelper.java ``` package com.exampl.mysql; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase.CursorFactory; import android.database.sqlite.SQLiteOpenHelper; import android.widget.Toast; public class DatabaseHelper extends SQLiteOpenHelper{ private Context mContext; public static final String CREATE_TABLE_SQL="create table dict(_id integer primary key autoincrement,word text,detail text);"; public DatabaseHelper(Context context,String name,CursorFactory factory,int version) { super(context,name,factory,version); mContext=context; } public void onCreate(SQLiteDatabase db) { db.execSQL(CREATE_TABLE_SQL); Toast.makeText(mContext,"创建成功!",Toast.LENGTH_LONG).show(); } public void onUpgrade(SQLiteDatabase db,int oldVersion,int newVersion) { } } ``` MainActivity.java ``` package com.exampl.mysql; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; import android.app.Activity; import android.content.Intent; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; public class MainActivity extends Activity implements OnClickListener{ private Button insert=null; private Button search=null; private EditText word=null; private EditText detail=null; private EditText key=null; DatabaseHelper dbHelper; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); dbHelper=new DatabaseHelper(this,"myDict.db3",null,1); insert=(Button)findViewById(R.id.insert); insert.setOnClickListener(this); search=(Button)findViewById(R.id.search); search.setOnClickListener(this); word=(EditText)findViewById(R.id.word); detail=(EditText)findViewById(R.id.detail); key=(EditText)findViewById(R.id.key); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.insert: String wor=word.getText().toString().trim(); String det=detail.getText().toString().trim(); insertData(dbHelper.getReadableDatabase(),wor,det); Toast.makeText(this, "添加生词成功!", Toast.LENGTH_LONG).show(); break; case R.id.search: String ke=key.getText().toString().trim(); Cursor cursor=dbHelper.getReadableDatabase().rawQuery("select*from dict where ? or ?", new String[]{"%"+ke+"%","%"+ke+"%"}); Bundle data=new Bundle(); data.putSerializable("date", converCursorToList(cursor)); Intent intent=new Intent(MainActivity.this,Result.class); intent.putExtras(data); startActivity(intent); break; default:break; } } protected ArrayList<Map<String,String>> converCursorToList(Cursor cursor) { ArrayList<Map<String,String>> result=new ArrayList<Map<String,String>>(); while (cursor.moveToNext()) { Map<String,String> map=new HashMap<String,String>(); map.put("word", cursor.getString(1)); map.put("detail", cursor.getString(2)); result.add(map); } return result; } private void insertData(SQLiteDatabase db,String word,String detail) { db.execSQL("insert into dict(word,detail) values(?,?)",new String[]{word,detail}); } @Override public void onDestroy() { super.onDestroy(); if (dbHelper!=null) dbHelper.close(); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } } ``` Result.java ``` package com.exampl.mysql; import android.app.Activity; import android.os.Bundle; import android.widget.TextView; public class Result extends Activity { private TextView jieguo=null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.line); jieguo=(TextView)findViewById(R.id.jieguo); Bundle bundle=getIntent().getExtras(); jieguo.setText(bundle.getString("date")); } } ```
android 按钮失灵 no keyboard for id 0
![图片说明](https://img-ask.csdn.net/upload/201805/26/1527295344_457538.png) 如图,添加按钮点击无反应,也没错误提示,就是在两个edittext输入时logcat有这样的警告 ![图片说明](https://img-ask.csdn.net/upload/201805/26/1527300050_502236.png) 代码如下: ``` import java.sql.Date; import java.text.SimpleDateFormat; import android.R.integer; import android.app.Activity; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.view.Window; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; public class AddFoodActivity1 extends Activity implements OnClickListener{ private MySQLiteOpenHelper dbHelper; private EditText sFoodName1,iEXP1; String foodsName1,foodsEXP1; int nameFlag,expFlag; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.add_food_activity1); sFoodName1 = (EditText) findViewById(R.id.et_foodName1); iEXP1 = (EditText) findViewById(R.id.et_EXP1); } @Override public void onClick(View v) { // TODO Auto-generated method stub // db.beginTransaction();//开启事务 if (v.getId() == R.id.bt_add1) { foodsName1 = sFoodName1.getText().toString(); foodsEXP1 = iEXP1.getText().toString(); dbHelper = MySQLiteOpenHelper.getInstance(this); SQLiteDatabase db = dbHelper.getWritableDatabase(); //查询是否已存在食物名称 Cursor cursor = db.rawQuery("select foodsName from food1 where foodsName=?", new String[]{foodsName1}); while (cursor.moveToNext()){ String name = cursor.getString(1); String exp = cursor.getString(2); if (foodsName1.isEmpty()){ Toast.makeText(AddFoodActivity1.this, "请输入食物名称", Toast.LENGTH_SHORT).show(); break; }else if(foodsEXP1.isEmpty()){ Toast.makeText(AddFoodActivity1.this, "请输入保质期", Toast.LENGTH_SHORT).show(); break; }else if (foodsName1.isEmpty()&&foodsEXP1.isEmpty()) { Toast.makeText(AddFoodActivity1.this, "请输入食物名称与保质期", Toast.LENGTH_SHORT).show(); break; } nameFlag = 1;//数据库没有此名 if (foodsName1.equals(name)) { Toast.makeText(AddFoodActivity1.this, "添加失败,食品名重复,请重新输入", Toast.LENGTH_SHORT).show(); nameFlag = 0; break; } } if (nameFlag == 1) { int trans = Integer.parseInt(foodsEXP1); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date curDate = new Date(System.currentTimeMillis()); String str=sdf.format(curDate); String exptime = str + trans*24*60*60*1000; db.execSQL("insert into food1 values (null,?,?)",new String[]{foodsName1,exptime}); // db.setTransactionSuccessful();//事务执行成功 // db.endTransaction();//结束事务 Toast.makeText(AddFoodActivity1.this, "添加成功", Toast.LENGTH_SHORT).show(); } cursor.close(); db.close(); } } } ``` 这是数据库 ``` import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteDatabase.CursorFactory; import android.database.sqlite.SQLiteOpenHelper; public class MySQLiteOpenHelper extends SQLiteOpenHelper { private static MySQLiteOpenHelper instance; public static final String CREATE_FOOD1 = "create table if not exists food1(id integer primary key autoincrement,foodsName varchar(20),EXP NUMERIC)"; public MySQLiteOpenHelper(Context context,String name, SQLiteDatabase.CursorFactory factory, int version) { super(context, name, factory, version); // TODO Auto-generated constructor stub } @Override public void onCreate(SQLiteDatabase db) { // TODO Auto-generated method stub db.execSQL(CREATE_FOOD1); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { // TODO Auto-generated method stub // db.execSQL("drop table if exists food"); // onCreate(db); } public static MySQLiteOpenHelper getInstance(Context context) { if (instance == null) { instance = new MySQLiteOpenHelper(context, "Food1.db", null, 2); } return instance; } } ``` cmd查看数据库发现表下没有column,感觉是数据库问题,但具体什么地方又不知道 ![图片说明](https://img-ask.csdn.net/upload/201805/26/1527300766_52620.png) ================================================= debug了一下,发现dbHelper这里可能死循环了,log cat里一直报那两行信息 ![图片说明](https://img-ask.csdn.net/upload/201805/26/1527317631_977270.png) ![图片说明](https://img-ask.csdn.net/upload/201805/26/1527317649_733305.png) ![图片说明](https://img-ask.csdn.net/upload/201805/26/1527317664_477381.png) 新手上路,求大神指教
再次添加表出错 安卓
OpenHelper文件中: public class OpenHelper extends SQLiteOpenHelper { //新建一个学生数据库 public OpenHelper(Context context) { super(context, "student.db", null, 1); } //创建一个学生表 public void onCreate(SQLiteDatabase db) { db.execSQL("create table student(id integer primary key autoincrement,name varchar(50),pwd varchar(50))"); } UserDao文件中: //通过用户名和密码查寻是否存在该学生 public int findStuBynamePWD(String name,String pwd){ int count = 0; SQLiteDatabase db = null; Cursor cursor = null; //执行创建数据库或是表的语句 db = openHelper.getReadableDatabase(); //执行通过用户名和密码的参数查询出用户,并保存在cursor中 cursor = db .rawQuery( "select count(*) as count from student where name=? and pwd=?", new String[] { name, pwd }); //得到的用户信息通过moveToNext()方法,while语句循环输出 while (cursor.moveToNext()) { //把 count = cursor.getInt(cursor.getColumnIndex("count")); } } LoginActivity文件关键代码中: UserDao userDao=new UserDao(LoginActivity.this); if(userDao.findStuBynamePWD(nameNum, pwdNum)>0){ //如果存在就跳到MainActivity startActivity(intent); } //用户名和密码输入有误! else{ Toast.makeText(LoginActivity.this, "用户名或密码有误,请重新输入!", Toast.LENGTH_SHORT).show(); } 问题:添加新表的时,在OpenHelper文件中,在onCreate方法中添加语句下面:db.execSQL("create table admin(a_id integer primary key autoincrement,a_name varchar(20),a_pwd varchar(20))"),我在SQLite语句是可以运行。运行工程时,没有新表?怎么改,跪求大神!!!
JAVA对数据库中列表进行操作出现PRIMARY KEY must be unique是什么原因
贴出代码求大神解答 String databaseFilename = DATABASE_PATH + "/" + DATABASE_FILENAME; db = SQLiteDatabase.openOrCreateDatabase(databaseFilename, null); db.execSQL("DROP TABLE IF EXISTS minfo"); db.execSQL("CREATE TABLE minfo (id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR, age SMALLINT, SingerName VARCHAR ,WordNum SMALLINT,ver SMALLINT,PyCode SMALLINT,Stroke SMALLINT,SingerName1 VARCHAR,SingerName2 VARCHAR,FileName SMALLINT,Lang VARCHAR,SongTypeID SMALLINT,SingerID1 SMALLINT,SingerID2 SMALLINT,MType SMALLINT,yTrack SMALLINT,bTrack SMALLINT,yVolume SMALLINT,bVolume SMALLINT,NewSong SMALLINT,style SMALLINT,SongNameSpell VARCHAR,SongNameSpell1 VARCHAR,SongNameSpell2 VARCHAR)"); final ContentValues cv1 = new ContentValues(); cv1.put("name", "aaaa"); // cv1.put("WordNum", "6"); cv1.put("ver", 6); cv1.put("age", "24"); // cv1.put("PyCode", "KD"); cv1.put("Stroke", 4); cv1.put("SingerName1", "lb"); cv1.put("SingerName2", "ja"); cv1.put("Lang", "0"); cv1.put("FileName", "3"); cv1.put("SongTypeID", 1); cv1.put("SingerID1", 123); cv1.put("SingerID2", 321); cv1.put("MType", 1); cv1.put("yTrack", 1); cv1.put("bTrack", 1); cv1.put("yVolume", 99); cv1.put("bVolume", 93); cv1.put("NewSong", 1); cv1.put("style", 9); cv1.put("SongNameSpell", "aaa"); cv1.put("SongNameSpell1", "bbb"); cv1.put("SongNameSpell2", "ccc"); db.insert("minfo", null, cv1); ContentValues cv2 = new ContentValues(); cv2.put("ver", 6); cv2.put("name", "ooom"); db.insert("minfo", null, cv2); ContentValues cv3 = new ContentValues(); cv3.put("ver", 40); cv3.put("name", "ognm"); db.insert("minfo", null, cv3); ContentValues cv4 = new ContentValues(); cv4.put("ver", 22); cv4.put("name", "fake"); db.insert("minfo", null, cv4); ``` ``` 这是我创建的数据库插入的数据 然后 new Thread(new Runnable() { @Override public void run() { // db.delete("minfo", null, null); db.execSQL("INSERT INTO minfo SELECT * FROM info "); // db.execSQL("CREATE TABLE minfo as SELECT * FROM info "); Cursor c = db.rawQuery("SELECT * FROM minfo", null); while (c.moveToNext()) { String w = c.getString(c.getColumnIndex("WordNum")); String p = c.getString(c.getColumnIndex("PyCode")); String songname = c.getString(c.getColumnIndex("name")); int id = c.getInt(c.getColumnIndex("id")); int ver = c.getInt(c.getColumnIndex("ver")); Log.i("本地数据库info表中的数 ", "id=" + id + ",name=" + songname + ",ver=" + ver + ",WordNum" + w + ",PyCode=" + p); } } }).start(); ``` ``` 想向minfo表中插入数据 然后报错 android.database.sqlite.SQLiteConstraintException: PRIMARY KEY must be unique (code 19) 是什么意思 我的info表的结构是 id=1,name=1111xxx,ver=132 id=5,name=xx,ver=23 请问这是什么原因造成的啊。。要怎样修改呢???
android怎么在listview中显示联系人 我的代码错在哪里??
package com.example.maysisteen; import java.util.ArrayList; import java.util.List; import android.os.Bundle; import android.R.anim; import android.app.Activity; import android.content.ContentValues; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.util.Log; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Adapter; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.ListView; public class MainActivity extends Activity { private ListView listView; private Button Submit; private List<String> list; //1.调用系统的“打开或创建数据库”方法来获得一个SQLiteDataBase对象 SQLiteDatabase db= openOrCreateDatabase("stu.db", MODE_PRIVATE, null); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //2.执行命令去创建表 db.execSQL("create table if not exists stutb (id integer primary key autoincrement," + "name text not null,sex text not null)"); //3.填充数据 ContentValues values=new ContentValues(); values.put("name", "张三"); values.put("sex", "男"); db.insert("stutb", null, values); values.clear(); //清空values后,可继续使用values对象 //5.将stutb表中, // 满足条件 id>?,其中条件值?为2, // id大于2的所有sex列更新为女。 values.put("sex", "女"); db.update("stutb", values, "id>?", new String[]{"2"}); values.clear(); listView=(ListView) findViewById(R.id.listView1); Submit=(Button) findViewById(R.id.submit); Submit.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub dd(); } }); } public void dd() { ArrayAdapter<String> adapter=new ArrayAdapter<String>(this ,android.R.layout.simple_list_item_1, ddv()); listView.setAdapter(adapter); } public final List<String> ddv() { Cursor cursor= db.query("stutb", null, "id>?", new String[]{"0"}, null, null, "name"); if (cursor!=null) { while (cursor.moveToNext()) { int id=cursor.getInt(cursor.getColumnIndex("id")); String name=cursor.getString(cursor.getColumnIndex("name")); String sex=cursor.getString(cursor.getColumnIndex("sex")); String value=id+""+name+""+sex+""; list.add(value); } } return list; } }
SQlite 数据库不能存储double 值为字符串
我使用下面的代码 public boolean addArea(AreaClass area , ArrayList<AreaMarkClass> areaArray) { area.id = getNextAreaId(); Log.d("longitude", area.longitude); Log.d("latitude", area.latitude); ContentValues initialValues = new ContentValues(); initialValues.put("_id", area.id); initialValues.put("name", area.name); initialValues.put("longitude", area.longitude); initialValues.put("latitude", area.latitude); initialValues.put("zoomLevel", area.zoomLevel); initialValues.put("creationDate",area.creationDate); try { mDb.insertOrThrow("TTArea", null, initialValues); } area.longitude 是一个字符串,它的值通过 `String.value (A Double Value)` 获得,现在通常是像 `22.323434523464563456` 但是当我检索这个值时: public AreaClass getAreaClassWithAreaId(Integer id) { String queryString = "SELECT * FROM TTArea WHERE _id = ?"; Cursor resultSet = mDb.rawQuery(queryString, new String[]{id.toString()}); AreaClass area = new AreaClass(); while(resultSet.moveToNext()) { area = new AreaClass( resultSet.getInt(resultSet.getColumnIndex("_id")), resultSet.getString(resultSet.getColumnIndex("name")), resultSet.getString(resultSet.getColumnIndex("longitude")), resultSet.getString(resultSet.getColumnIndex("latitude")), resultSet.getString(resultSet.getColumnIndex("zoomLevel")), resultSet.getString(resultSet.getColumnIndex("creationDate")) ); } resultSet.close(); return area; } 大约是 `22.3234`。 在我的程序中我需要存储精确的数值。如何处理这个问题?
Kafka实战(三) - Kafka的自我修养与定位
Apache Kafka是消息引擎系统,也是一个分布式流处理平台(Distributed Streaming Platform) Kafka是LinkedIn公司内部孵化的项目。LinkedIn最开始有强烈的数据强实时处理方面的需求,其内部的诸多子系统要执行多种类型的数据处理与分析,主要包括业务系统和应用程序性能监控,以及用户行为数据处理等。 遇到的主要问题: 数据正确性不足 数据的收集主要...
volatile 与 synchronize 详解
Java支持多个线程同时访问一个对象或者对象的成员变量,由于每个线程可以拥有这个变量的拷贝(虽然对象以及成员变量分配的内存是在共享内存中的,但是每个执行的线程还是可以拥有一份拷贝,这样做的目的是加速程序的执行,这是现代多核处理器的一个显著特性),所以程序在执行过程中,一个线程看到的变量并不一定是最新的。 volatile 关键字volatile可以用来修饰字段(成员变量),就是告知程序任何对该变量...
Java学习的正确打开方式
在博主认为,对于入门级学习java的最佳学习方法莫过于视频+博客+书籍+总结,前三者博主将淋漓尽致地挥毫于这篇博客文章中,至于总结在于个人,实际上越到后面你会发现学习的最好方式就是阅读参考官方文档其次就是国内的书籍,博客次之,这又是一个层次了,这里暂时不提后面再谈。博主将为各位入门java保驾护航,各位只管冲鸭!!!上天是公平的,只要不辜负时间,时间自然不会辜负你。 何谓学习?博主所理解的学习,它是一个过程,是一个不断累积、不断沉淀、不断总结、善于传达自己的个人见解以及乐于分享的过程。
程序员必须掌握的核心算法有哪些?
由于我之前一直强调数据结构以及算法学习的重要性,所以就有一些读者经常问我,数据结构与算法应该要学习到哪个程度呢?,说实话,这个问题我不知道要怎么回答你,主要取决于你想学习到哪些程度,不过针对这个问题,我稍微总结一下我学过的算法知识点,以及我觉得值得学习的算法。这些算法与数据结构的学习大多数是零散的,并没有一本把他们全部覆盖的书籍。下面是我觉得值得学习的一些算法以及数据结构,当然,我也会整理一些看过...
有哪些让程序员受益终生的建议
从业五年多,辗转两个大厂,出过书,创过业,从技术小白成长为基层管理,联合几个业内大牛回答下这个问题,希望能帮到大家,记得帮我点赞哦。 敲黑板!!!读了这篇文章,你将知道如何才能进大厂,如何实现财务自由,如何在工作中游刃有余,这篇文章很长,但绝对是精品,记得帮我点赞哦!!!! 一腔肺腑之言,能看进去多少,就看你自己了!!! 目录: 在校生篇: 为什么要尽量进大厂? 如何选择语言及方...
大学四年自学走来,这些私藏的实用工具/学习网站我贡献出来了
大学四年,看课本是不可能一直看课本的了,对于学习,特别是自学,善于搜索网上的一些资源来辅助,还是非常有必要的,下面我就把这几年私藏的各种资源,网站贡献出来给你们。主要有:电子书搜索、实用工具、在线视频学习网站、非视频学习网站、软件下载、面试/求职必备网站。 注意:文中提到的所有资源,文末我都给你整理好了,你们只管拿去,如果觉得不错,转发、分享就是最大的支持了。 一、电子书搜索 对于大部分程序员...
linux系列之常用运维命令整理笔录
本博客记录工作中需要的linux运维命令,大学时候开始接触linux,会一些基本操作,可是都没有整理起来,加上是做开发,不做运维,有些命令忘记了,所以现在整理成博客,当然vi,文件操作等就不介绍了,慢慢积累一些其它拓展的命令,博客不定时更新 free -m 其中:m表示兆,也可以用g,注意都要小写 Men:表示物理内存统计 total:表示物理内存总数(total=used+free) use...
比特币原理详解
一、什么是比特币 比特币是一种电子货币,是一种基于密码学的货币,在2008年11月1日由中本聪发表比特币白皮书,文中提出了一种去中心化的电子记账系统,我们平时的电子现金是银行来记账,因为银行的背后是国家信用。去中心化电子记账系统是参与者共同记账。比特币可以防止主权危机、信用风险。其好处不多做赘述,这一层面介绍的文章很多,本文主要从更深层的技术原理角度进行介绍。 二、问题引入 假设现有4个人...
GitHub开源史上最大规模中文知识图谱
近日,一直致力于知识图谱研究的 OwnThink 平台在 Github 上开源了史上最大规模 1.4 亿中文知识图谱,其中数据是以(实体、属性、值),(实体、关系、实体)混合的形式组织,数据格式采用 csv 格式。 到目前为止,OwnThink 项目开放了对话机器人、知识图谱、语义理解、自然语言处理工具。知识图谱融合了两千五百多万的实体,拥有亿级别的实体属性关系,机器人采用了基于知识图谱的语义感...
程序员接私活怎样防止做完了不给钱?
首先跟大家说明一点,我们做 IT 类的外包开发,是非标品开发,所以很有可能在开发过程中会有这样那样的需求修改,而这种需求修改很容易造成扯皮,进而影响到费用支付,甚至出现做完了项目收不到钱的情况。 那么,怎么保证自己的薪酬安全呢? 我们在开工前,一定要做好一些证据方面的准备(也就是“讨薪”的理论依据),这其中最重要的就是需求文档和验收标准。一定要让需求方提供这两个文档资料作为开发的基础。之后开发...
网页实现一个简单的音乐播放器(大佬别看。(⊙﹏⊙))
今天闲着无事,就想写点东西。然后听了下歌,就打算写个播放器。 于是乎用h5 audio的加上js简单的播放器完工了。 演示地点演示 html代码如下` music 这个年纪 七月的风 音乐 ` 然后就是css`*{ margin: 0; padding: 0; text-decoration: none; list-...
微信支付崩溃了,但是更让马化腾和张小龙崩溃的竟然是……
loonggg读完需要3分钟速读仅需1分钟事件还得还原到昨天晚上,10 月 29 日晚上 20:09-21:14 之间,微信支付发生故障,全国微信支付交易无法正常进行。然...
Python十大装B语法
Python 是一种代表简单思想的语言,其语法相对简单,很容易上手。不过,如果就此小视 Python 语法的精妙和深邃,那就大错特错了。本文精心筛选了最能展现 Python 语法之精妙的十个知识点,并附上详细的实例代码。如能在实战中融会贯通、灵活使用,必将使代码更为精炼、高效,同时也会极大提升代码B格,使之看上去更老练,读起来更优雅。
数据库优化 - SQL优化
以实际SQL入手,带你一步一步走上SQL优化之路!
2019年11月中国大陆编程语言排行榜
2019年11月2日,我统计了某招聘网站,获得有效程序员招聘数据9万条。针对招聘信息,提取编程语言关键字,并统计如下: 编程语言比例 rank pl_ percentage 1 java 33.62% 2 cpp 16.42% 3 c_sharp 12.82% 4 javascript 12.31% 5 python 7.93% 6 go 7.25% 7 p...
通俗易懂地给女朋友讲:线程池的内部原理
餐盘在灯光的照耀下格外晶莹洁白,女朋友拿起红酒杯轻轻地抿了一小口,对我说:“经常听你说线程池,到底线程池到底是个什么原理?”
《奇巧淫技》系列-python!!每天早上八点自动发送天气预报邮件到QQ邮箱
将代码部署服务器,每日早上定时获取到天气数据,并发送到邮箱。 也可以说是一个小型人工智障。 知识可以运用在不同地方,不一定非是天气预报。
经典算法(5)杨辉三角
杨辉三角 是经典算法,这篇博客对它的算法思想进行了讲解,并有完整的代码实现。
英特尔不为人知的 B 面
从 PC 时代至今,众人只知在 CPU、GPU、XPU、制程、工艺等战场中,英特尔在与同行硬件芯片制造商们的竞争中杀出重围,且在不断的成长进化中,成为全球知名的半导体公司。殊不知,在「刚硬」的背后,英特尔「柔性」的软件早已经做到了全方位的支持与支撑,并持续发挥独特的生态价值,推动产业合作共赢。 而对于这一不知人知的 B 面,很多人将其称之为英特尔隐形的翅膀,虽低调,但是影响力却不容小觑。 那么,在...
腾讯算法面试题:64匹马8个跑道需要多少轮才能选出最快的四匹?
昨天,有网友私信我,说去阿里面试,彻底的被打击到了。问了为什么网上大量使用ThreadLocal的源码都会加上private static?他被难住了,因为他从来都没有考虑过这个问题。无独有偶,今天笔者又发现有网友吐槽了一道腾讯的面试题,我们一起来看看。 腾讯算法面试题:64匹马8个跑道需要多少轮才能选出最快的四匹? 在互联网职场论坛,一名程序员发帖求助到。二面腾讯,其中一个算法题:64匹...
面试官:你连RESTful都不知道我怎么敢要你?
干货,2019 RESTful最贱实践
刷了几千道算法题,这些我私藏的刷题网站都在这里了!
遥想当年,机缘巧合入了 ACM 的坑,周边巨擘林立,从此过上了"天天被虐似死狗"的生活… 然而我是谁,我可是死狗中的战斗鸡,智力不够那刷题来凑,开始了夜以继日哼哧哼哧刷题的日子,从此"读题与提交齐飞, AC 与 WA 一色 ",我惊喜的发现被题虐既刺激又有快感,那一刻我泪流满面。这么好的事儿作为一个正直的人绝不能自己独享,经过激烈的颅内斗争,我决定把我私藏的十几个 T 的,阿不,十几个刷题网...
为啥国人偏爱Mybatis,而老外喜欢Hibernate/JPA呢?
关于SQL和ORM的争论,永远都不会终止,我也一直在思考这个问题。昨天又跟群里的小伙伴进行了一番讨论,感触还是有一些,于是就有了今天这篇文。 声明:本文不会下关于Mybatis和JPA两个持久层框架哪个更好这样的结论。只是摆事实,讲道理,所以,请各位看官勿喷。 一、事件起因 关于Mybatis和JPA孰优孰劣的问题,争论已经很多年了。一直也没有结论,毕竟每个人的喜好和习惯是大不相同的。我也看...
白话阿里巴巴Java开发手册高级篇
不久前,阿里巴巴发布了《阿里巴巴Java开发手册》,总结了阿里巴巴内部实际项目开发过程中开发人员应该遵守的研发流程规范,这些流程规范在一定程度上能够保证最终的项目交付质量,通过在时间中总结模式,并推广给广大开发人员,来避免研发人员在实践中容易犯的错误,确保最终在大规模协作的项目中达成既定目标。 无独有偶,笔者去年在公司里负责升级和制定研发流程、设计模板、设计标准、代码标准等规范,并在实际工作中进行...
SQL-小白最佳入门sql查询一
不要偷偷的查询我的个人资料,即使你再喜欢我,也不要这样,真的不好;
项目中的if else太多了,该怎么重构?
介绍 最近跟着公司的大佬开发了一款IM系统,类似QQ和微信哈,就是聊天软件。我们有一部分业务逻辑是这样的 if (msgType = "文本") { // dosomething } else if(msgType = "图片") { // doshomething } else if(msgType = "视频") { // doshomething } else { // doshom...
Nginx 原理和架构
Nginx 是一个免费的,开源的,高性能的 HTTP 服务器和反向代理,以及 IMAP / POP3 代理服务器。Nginx 以其高性能,稳定性,丰富的功能,简单的配置和低资源消耗而闻名。 Nginx 的整体架构 Nginx 里有一个 master 进程和多个 worker 进程。master 进程并不处理网络请求,主要负责调度工作进程:加载配置、启动工作进程及非停升级。worker 进程负责处...
YouTube排名第一的励志英文演讲《Dream(梦想)》
Idon’t know what that dream is that you have, I don't care how disappointing it might have been as you've been working toward that dream,but that dream that you’re holding in your mind, that it’s po...
“狗屁不通文章生成器”登顶GitHub热榜,分分钟写出万字形式主义大作
一、垃圾文字生成器介绍 最近在浏览GitHub的时候,发现了这样一个骨骼清奇的雷人项目,而且热度还特别高。 项目中文名:狗屁不通文章生成器 项目英文名:BullshitGenerator 根据作者的介绍,他是偶尔需要一些中文文字用于GUI开发时测试文本渲染,因此开发了这个废话生成器。但由于生成的废话实在是太过富于哲理,所以最近已经被小伙伴们给玩坏了。 他的文风可能是这样的: 你发现,...
程序员:我终于知道post和get的区别
是一个老生常谈的话题,然而随着不断的学习,对于以前的认识有很多误区,所以还是需要不断地总结的,学而时习之,不亦说乎
相关热词 c# clr dll c# 如何orm c# 固定大小的字符数组 c#框架设计 c# 删除数据库 c# 中文文字 图片转 c# 成员属性 接口 c#如何将程序封装 16进制负数转换 c# c#练手项目
立即提问

相似问题

11
关于Java中long 型转换为Integer类型的问题
5
Mysql 设置字段默认值0 插入数据后 却显示null
6
android 按钮失灵 no keyboard for id 0
15
关于从jsp页面提交数据到数据库出现乱码的问题
8
关于 安卓数据库查询问题 怎样将查询到的信息存入数组 再用bundler传递
3
Firebird创建了一个BWL的表,里面有个ID字段是INTEGER类型,怎么设置自动增加的呢?
8
同一条SQL语句,myBatis查出来的数据和Navicat查出来的数据不同
5
eclipse连接数据库问题:捕捉到异常“数据源错误”,帮帮孩子吧...代码如下
3
使用Android中的SQLite建立一个数据库,加了一张Book表,增加一个表,升级数据库失败
3
每次都自动执行到master数据库,能默认执行到我创建的数据库吗,
2
ajax校验数据库数据是否存在
1
map中泛型定义的Integer类型,但是数据库查询数据后竟然赋值为Long类型?具体见详情附图
2
SQLite在模拟器6.0不能创建表,db.execSQL()语句没有执行
1
java层面List<Integer>与List<Double>是两个不同的类型
3
hibernate 连接数据库报错 获取xml失败 求大佬帮忙看一下
3
Java读取文本数据存到数据库,在方法执行完成后为啥所占用的内存资源没释放?
1
一个有关数据库遇到的算法障碍的问题怎么解决?C语言
4
SpringBootWEB项目数据库连接关闭异常
0
为什么我delect有些数据库里的数据删不掉
3
js获取后台返回的ajax数据 , 是Integer集合 , 现在想遍历这个data