while (rs.next()) { String id = rs.getString("country_id"); // Column 1
2012-11-01 11:09
113 查看
import java.sql.*; import org.sqlite.JDBC; public class SQLiteTest { public static void main(String[] args) { try { // The SQLite (3.3.8) Database File // This database has one table (pmp_countries) with 3 columns (country_id, country_code, country_name) // It has like 237 records of all the countries I could think of. String fileName = "c:/pmp.db"; // Driver to Use // http://www.zentus.com/sqlitejdbc/index.html Class.forName("org.sqlite.JDBC"); // Create Connection Object to SQLite Database // If you want to only create a database in memory, exclude the +fileName Connection conn = DriverManager.getConnection("jdbc:sqlite:"+fileName); // Create a Statement object for the database connection, dunno what this stuff does though. Statement stmt = conn.createStatement(); // Create a result set object for the statement ResultSet rs = stmt.executeQuery("SELECT * FROM pmp_countries ORDER BY country_name ASC"); // Iterate the result set, printing each column // if the column was an int, we could do rs.getInt(column name here) as well, etc. while (rs.next()) { String id = rs.getString("country_id"); // Column 1 String code = rs.getString("country_code"); // Column 2 String name = rs.getString("country_name"); // Column 3 System.out.println("ID: "+id+" Code: "+code+" Name: "+name); } // Close the connection conn.close(); } catch (Exception e) { // Print some generic debug info System.out.println(e.getMessage()); System.out.println(e.toString()); } } }
相关文章推荐
- 解决当字段不存在使用resultSet.getString("id")报异常的问题
- request.querystring("id")与request("id")区别在哪!
- Request.QueryString[""],Request.QueryString.Get()以及Request.Form[""],Request.Form.Get区别
- $("#id").html(代码内容) VS document.getElementById("id").innerHTML="代码内容";
- while select 的另一种实现方式"Next Table"
- $("#id")与document.getElementById("id") 即 jQuery对象和DOM对象相互转换
- 解决:java.lang.NumberFormatException: For input string: "id"
- Ext.getCmp("id") 简单应用
- jQuery的$("#id")和document.getElementById("id")的区别
- mysql 错误 SQL Error: 1366: Incorrect string value: "\xE8\xAF\xA6\xE7\xBB\x86…" for column "address" a
- 问题解决: Attribute value request.getParameter("id") is quoted with " which must be escaped when used within the value
- 问题:For input string: "id"
- (Entlib 5.0)Activation error occured while trying to get instance of type ICacheManager, key ""求解决办法
- 使用rs.next()提示"Unhandled exception type SQLException"两种解决方法
- String.getByte("utf-8")和new String(byte[],"utf-8")各是什么意思?
- Error: An App ID with identifier "*****" is not avaliable. Please enter a different string.
- org.postgresql.util.PSQLException: ERROR: column "loginid" of relation "userinfo" does not exist
- java判断request.getParameter("Id")为合法数字,而不包含其他除过数字的字符
- column: xxxxxx_ID (should be mapped with insert="false" update="false")
- Request.QueryString["id"]跟Request["id"]的区别