public class Config {
//数据库的名字
public static final String DATABASE_NAME = "student.db";
//表名
public static final String TABLE_NAME = "student";
//数据库版本号
public static final int DB_VERSION = 1;
}
SQLiteHelper文件:
public class SQLiteHelper extends SQLiteOpenHelper {
public SQLiteHelper(Context context) {
super(context, Config.DATABASE_NAME, null, Config.DB_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
//创建表:
db.execSQL("create table if not exists student(_id integer primary key autoincrement,Id INT(10),name VARCHAR(10),age INT(4),sex VARCHAR(10),birth VARCHAR(10),department VARCHAR(10),address VARCHAR(100),chinesScore DOUBLE(10),englishScore DOUBLE(10))");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
}
DBUtils文件:
public class DBUtils {
private Context context;
private SQLiteHelper helper;
//最好使用单例模式
public DBUtils(Context context) {
this.context = context;
helper = new SQLiteHelper(context);
}
/**
* 向表中插入一个学生
*
* @param student
* @return
*/
public boolean insertData(Student student) {
SQLiteDatabase db = helper.getReadableDatabase();
ContentValues values = new ContentValues();
values.put("Id", student.getId());
values.put("name", student.getName());
values.put("age", student.getAge());
values.put("sex", student.getSex());
values.put("birth", student.getBirth());
values.put("department", student.getDepartment());
values.put("address", student.getAddress());
values.put("chinesScore", student.getChinesScore());
values.put("englishScore", student.getEnglishScore());
long insert = db.insert(Config.TABLE_NAME, null, values);
if (insert > 0) {
return true;
}
return false;
}
/**
* 查询全部的学生数据信息
*
* @return
*/
public List<Student> getAllStudent() {
List<Student> list = new ArrayList<>();
SQLiteDatabase db = helper.getReadableDatabase();
Cursor cursor = db.rawQuery("select * from " + Config.TABLE_NAME, null);
if (cursor != null && cursor.getCount() > 0) {
while (cursor.moveToNext()) {
int id = cursor.getInt(cursor.getColumnIndex("Id"));
String name = cursor.getString(cursor.getColumnIndex("name"));
int age = cursor.getInt(cursor.getColumnIndex("age"));
String sex = cursor.getString(cursor.getColumnIndex("sex"));
String birth = cursor.getString(cursor.getColumnIndex("birth"));
String department = cursor.getString(cursor.getColumnIndex("department"));
String address = cursor.getString(cursor.getColumnIndex("address"));
double chinesScore = cursor.getDouble(cursor.getColumnIndex("chinesScore"));
double englishScore = cursor.getDouble(cursor.getColumnIndex("englishScore"));
Student student = new Student(id, name, age, sex, birth, department, address, chinesScore, englishScore);
list.add(student);
}
}
return list;
}
/**
* 查询学生表信息,只显示名字,院系,和学号
*
* @return
*/
public List<Student> getStudentNameAndCode() {
List<Student> list = new ArrayList<>();
SQLiteDatabase db = helper.getReadableDatabase();
Cursor cursor = db.rawQuery("select * from " + Config.TABLE_NAME, null);
if (cursor != null && cursor.getCount() > 0) {
while (cursor.moveToNext()) {
int id = cursor.getInt(cursor.getColumnIndex("Id"));
String name = cursor.getString(cursor.getColumnIndex("name"));
String department = cursor.getString(cursor.getColumnIndex("department"));
Student student = new Student(id, name, 0, "", "", department, "", 0, 0);
list.add(student);
}
}
return list;
}
/**
* 查询显示计算机和英语系学生的成绩
*
* @return
*/
public List<Student> getAllStudentEnglshAndCompute() {
List<Student> list = new ArrayList<>();
SQLiteDatabase db = helper.getReadableDatabase();
Cursor cursor = db.rawQuery("select * from " + Config.TABLE_NAME + " where department in ('英语系' , '计算机')", null);
if (cursor != null && cursor.getCount() > 0) {
while (cursor.moveToNext()) {
int id = cursor.getInt(cursor.getColumnIndex("Id"));
String name = cursor.getString(cursor.getColumnIndex("name"));
int age = cursor.getInt(cursor.getColumnIndex("age"));
String sex = cursor.getString(cursor.getColumnIndex("sex"));
String birth = cursor.getString(cursor.getColumnIndex("birth"));
String department = cursor.getString(cursor.getColumnIndex("department"));
String address = cursor.getString(cursor.getColumnIndex("address"));
double chinesScore = cursor.getDouble(cursor.getColumnIndex("chinesScore"));
double englishScore = cursor.getDouble(cursor.getColumnIndex("englishScore"));
Student student = new Student(id, name, age, sex, birth, department, address, chinesScore, englishScore);
list.add(student);
}
}
return list;
}
/**
* 查询18-22岁学生的成绩
*
* @return
*/
public List<Student> getAllStudentAge() {
List<Student> list = new ArrayList<>();
SQLiteDatabase db = helper.getReadableDatabase();
Cursor cursor = db.rawQuery("select * from " + Config.TABLE_NAME + " where age > 18 and age < 22", null);
if (cursor != null && cursor.getCount() > 0) {
while (cursor.moveToNext()) {
int id = cursor.getInt(cursor.getColumnIndex("Id"));
String name = cursor.getString(cursor.getColumnIndex("name"));
int age = cursor.getInt(cursor.getColumnIndex("age"));
String sex = cursor.getString(cursor.getColumnIndex("sex"));
String birth = cursor.getString(cursor.getColumnIndex("birth"));
String department = cursor.getString(cursor.getColumnIndex("department"));
String address = cursor.getString(cursor.getColumnIndex("address"));
double chinesScore = cursor.getDouble(cursor.getColumnIndex("chinesScore"));
double englishScore = cursor.getDouble(cursor.getColumnIndex("englishScore"));
Student student = new Student(id, name, age, sex, birth, department, address, chinesScore, englishScore);
list.add(student);
}
}
return list;
}
/**
* 查询表中有共有多少条数据
*
* @return
*/
public int getStudentCount() {
SQLiteDatabase db = helper.getReadableDatabase();
Cursor cursor = db.rawQuery("select * from " + Config.TABLE_NAME, null);
return cursor.getCount();
}
/**
* 查询成绩表中分数最高的学生信息
*/
public List<Student> getAllStudentScore() {
List<Student> list = new ArrayList<>();
SQLiteDatabase db = helper.getReadableDatabase();
//降序的方式排列查询数据desc 升序 asc
Cursor cursor = db.rawQuery("select * from " + Config.TABLE_NAME + " order by chinesScore desc", null);
if (cursor != null && cursor.getCount() > 0) {
//取出第一个 就是最高分
while (cursor.moveToFirst()) {
int id = cursor.getInt(cursor.getColumnIndex("Id"));
String name = cursor.getString(cursor.getColumnIndex("name"));
int age = cursor.getInt(cursor.getColumnIndex("age"));
String sex = cursor.getString(cursor.getColumnIndex("sex"));
String birth = cursor.getString(cursor.getColumnIndex("birth"));
String department = cursor.getString(cursor.getColumnIndex("department"));
String address = cursor.getString(cursor.getColumnIndex("address"));
double chinesScore = cursor.getDouble(cursor.getColumnIndex("chinesScore"));
double englishScore = cursor.getDouble(cursor.getColumnIndex("englishScore"));
Student student = new Student(id, name, age, sex, birth, department, address, chinesScore, englishScore);
list.add(student);
break;
}
}
return list;
}
/**
* 查询显示名字叫李四的学生信息
*
* @return
*/
public List<Student> getStudentLisi() {
List<Student> list = new ArrayList<>();
SQLiteDatabase db = helper.getReadableDatabase();
Cursor cursor = db.rawQuery("select * from " + Config.TABLE_NAME + " where name = '李四'", null);
if (cursor != null && cursor.getCount() > 0) {
while (cursor.moveToFirst()) {
int id = cursor.getInt(cursor.getColumnIndex("Id"));
String name = cursor.getString(cursor.getColumnIndex("name"));
int age = cursor.getInt(cursor.getColumnIndex("age"));
String sex = cursor.getString(cursor.getColumnIndex("sex"));
String birth = cursor.getString(cursor.getColumnIndex("birth"));
String department = cursor.getString(cursor.getColumnIndex("department"));
String address = cursor.getString(cursor.getColumnIndex("address"));
double chinesScore = cursor.getDouble(cursor.getColumnIndex("chinesScore"));
double englishScore = cursor.getDouble(cursor.getColumnIndex("englishScore"));
Student student = new Student(id, name, age, sex, birth, department, address, chinesScore, englishScore);
list.add(student);
break;
}
}
return list;
}
/**
* 获取语文成绩的总和
*
* @return
*/
public double getAllStudentChineseScoreTotal() {
double total = 0;
SQLiteDatabase db = helper.getReadableDatabase();
Cursor cursor = db.rawQuery("select * from " + Config.TABLE_NAME, null);
if (cursor != null && cursor.getCount() > 0) {
while (cursor.moveToNext()) {
double chinesScore = cursor.getDouble(cursor.getColumnIndex("chinesScore"));
total += chinesScore;
}
}
return total;
}
/**
* 获取英语的平均成绩
* @return
*/
public double getAllStudentEnglishScore() {
double total = 0;
SQLiteDatabase db = helper.getReadableDatabase();
Cursor cursor = db.rawQuery("select * from " + Config.TABLE_NAME, null);
if (cursor != null && cursor.getCount() > 0) {
while (cursor.moveToNext()) {
double englishScore = cursor.getDouble(cursor.getColumnIndex("englishScore"));
total += englishScore;
}
}
return total/cursor.getCount();
}
}
Student自定义学生类文件:
public class Student {
private int Id;
private String name;
private int age;
private String sex;
private String birth;
private String department;
private String address;
private double chinesScore;
private double englishScore;
public Student(int id, String name, int age, String sex, String birth, String department, String address, double chinesScore, double englishScore) {
Id = id;
this.name = name;
this.age = age;
this.sex = sex;
this.birth = birth;
this.department = department;
this.address = address;
this.chinesScore = chinesScore;
this.englishScore = englishScore;
}
public int getId() {
return Id;
}
public void setId(int id) {
Id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String getBirth() {
return birth;
}
public void setBirth(String birth) {
this.birth = birth;
}
public String getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public double getChinesScore() {
return chinesScore;
}
public void setChinesScore(double chinesScore) {
this.chinesScore = chinesScore;
}
public double getEnglishScore() {
return englishScore;
}
public void setEnglishScore(double englishScore) {
this.englishScore = englishScore;
}
@Override
public String toString() {
return "Student{" +
"Id=" + Id +
", name='" + name + '\'' +
", age=" + age +
", sex='" + sex + '\'' +
", birth='" + birth + '\'' +
", department='" + department + '\'' +
", address='" + address + '\'' +
", chinesScore=" + chinesScore +
", englishScore=" + englishScore +
'}';
}
}
package gaodai.matrix;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner scanner = new Sc
Asynchronous Http Client是android中非常好的异步请求工具
除了异步之外还有很多封装比如json的处理,cookie的处理
引用
Persistent Cookie Storage with PersistentCookieStore
This library also includes a PersistentCookieStore whi
安装Apache问题:系统找不到指定的文件 No installed service named "Apache2"
每次到这一步都很小心防它的端口冲突问题,结果,特意留出来的80端口就是不能用,烦。
解决方法确保几处:
1、停止IIS启动
2、把端口80改成其它 (譬如90,800,,,什么数字都好)
3、防火墙(关掉试试)
在运行处输入 cmd 回车,转到apa
问题描述:
MongoDB在非正常情况下关闭时,可能会导致索引文件破坏,造成数据在更新时没有反映到索引上。
解决方案:
使用脚本,重建MongoDB所有表的索引。
var names = db.getCollectionNames();
for( var i in names ){
var name = names[i];
print(name);
Zookeeper重载了几个构造函数,其中构造者可以提供参数最多,可定制性最多的构造函数是
public ZooKeeper(String connectString, int sessionTimeout, Watcher watcher, long sessionId, byte[] sessionPasswd, boolea
本文转自:http://hatemysql.com/2010/06/29/select-into-outfile-access-deny%E9%97%AE%E9%A2%98/
为应用建立了rnd的帐号,专门为他们查询线上数据库用的,当然,只有他们上了生产网络以后才能连上数据库,安全方面我们还是很注意的,呵呵。
授权的语句如下:
grant select on armory.* to rn
<?php
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
if (PHP_SAPI == 'cli')
die('This example should only be run from a Web Brows
1. I see. 我明白了。2. I quit! 我不干了!3. Let go! 放手!4. Me too. 我也是。5. My god! 天哪!6. No way! 不行!7. Come on. 来吧(赶快)8. Hold on. 等一等。9. I agree。 我同意。10. Not bad. 还不错。11. Not yet. 还没。12. See you. 再见。13. Shut up!
基本事务的使用:
从账户一的余额中转100到账户二的余额中去,如果账户二不存在或账户一中的余额不足100则整笔交易回滚
select * from account;
-- 创建一张账户表
create table account(
-- 账户ID
id number(3) not null,
-- 账户名称
nam