SQLite插入数据 5
添加数据的服务代码是这么写的/***添加记录*@paramperson*/publicvoidsava(Personperson){SQLiteDatabasedb=db...
添加数据的服务代码是这么写的
/**
* 添加记录
* @param person
*/
public void sava(Person person){
SQLiteDatabase db=dbOpenHelper.getWritableDatabase();
db.execSQL("insert into person(name,phone)values(?,?)",
new Object[]{person.getName(),person.getPhone()});
db.close();
}
那这里要插入数据代码该怎么写?
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_xq1);
listView=(ListView) findViewById(R.id.listView);
mgr=new PersonService(this);
}
public void save(Person person){
//插入数据的代码
} 展开
/**
* 添加记录
* @param person
*/
public void sava(Person person){
SQLiteDatabase db=dbOpenHelper.getWritableDatabase();
db.execSQL("insert into person(name,phone)values(?,?)",
new Object[]{person.getName(),person.getPhone()});
db.close();
}
那这里要插入数据代码该怎么写?
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_xq1);
listView=(ListView) findViewById(R.id.listView);
mgr=new PersonService(this);
}
public void save(Person person){
//插入数据的代码
} 展开
展开全部
/**
* 注释部分就有插入的操作
*/
package sqlIte;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
/**
* @author Administrator
*
*/
public class Test {
/**
* @author : haoming
* @date : 2012-11-28上午10:02:36
* @111 sqlIte.SqlIteTest.java.main
* @returnType : void
* @desc :
*/
public static void main(String[] args) {
Connection conn = null;
Statement stat = null;
ResultSet rs=null;
try {
Class.forName("org.sqlite.JDBC");
conn = DriverManager.getConnection("jdbc:sqlite:test.db");
conn.setAutoCommit(false);
stat = conn.createStatement();
// stat.executeUpdate("create table people (name, occupation);");
// stat.executeUpdate("insert into people values ('Gandhi', 'politics');");
// stat.executeUpdate("insert into people values ('Turing', 'computers');");
// stat.executeUpdate("insert into people values ('Wittgenstein', 'smartypants');");
conn.commit();
rs = stat.executeQuery("pragma table_info(people)");
while(rs.next()){
System.out.println(rs.getString("cid")+"~"+rs.getString("name")+"~"+rs.getString("type")+"~"+rs.getString("notnull")+"~"+rs.getString("dflt_value")+"~"+rs.getString("pk"));
}
rs = stat.executeQuery("select * from people;");
while (rs.next()) {
System.out.println("name = " + rs.getString("name"));
System.out.println("occupation = " + rs.getString("occupation"));
}
rs.close();
conn.close();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
* 注释部分就有插入的操作
*/
package sqlIte;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
/**
* @author Administrator
*
*/
public class Test {
/**
* @author : haoming
* @date : 2012-11-28上午10:02:36
* @111 sqlIte.SqlIteTest.java.main
* @returnType : void
* @desc :
*/
public static void main(String[] args) {
Connection conn = null;
Statement stat = null;
ResultSet rs=null;
try {
Class.forName("org.sqlite.JDBC");
conn = DriverManager.getConnection("jdbc:sqlite:test.db");
conn.setAutoCommit(false);
stat = conn.createStatement();
// stat.executeUpdate("create table people (name, occupation);");
// stat.executeUpdate("insert into people values ('Gandhi', 'politics');");
// stat.executeUpdate("insert into people values ('Turing', 'computers');");
// stat.executeUpdate("insert into people values ('Wittgenstein', 'smartypants');");
conn.commit();
rs = stat.executeQuery("pragma table_info(people)");
while(rs.next()){
System.out.println(rs.getString("cid")+"~"+rs.getString("name")+"~"+rs.getString("type")+"~"+rs.getString("notnull")+"~"+rs.getString("dflt_value")+"~"+rs.getString("pk"));
}
rs = stat.executeQuery("select * from people;");
while (rs.next()) {
System.out.println("name = " + rs.getString("name"));
System.out.println("occupation = " + rs.getString("occupation"));
}
rs.close();
conn.close();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
光点科技
2023-08-15 广告
2023-08-15 广告
通常情况下,我们会按照结构模型把系统产生的数据分为三种类型:结构化数据、半结构化数据和非结构化数据。结构化数据,即行数据,是存储在数据库里,可以用二维表结构来逻辑表达实现的数据。最常见的就是数字数据和文本数据,它们可以某种标准格式存在于文件...
点击进入详情页
本回答由光点科技提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |