2012-02-14 124 views
0

我在系統的桌面上有一個名爲localEntry.sqlite的SQLite數據庫文件。我想讀取這個數據庫的表格之一的數據。爲此,我寫在Eclipse代碼訪問所有的數據形式的表的一個:SQLite連接字符串配置

public class SqliteDbRead { 

private static String col1; 
private static String col2; 


public static void main(String[] args) throws 
    SQLException, ClassNotFoundException { 

    //Get Connection 
    Class.forName("org.sqlite.JDBC"); 
    Connection con = DriverManager.getConnection("jdbc:sqlite:localEntry.sqlite"); 

    //obtain a statement 
    Statement st = con.createStatement(); 
    String query = "select * from submitted_table"; 

    //Execute Query 
    ResultSet rs = st.executeQuery(query); 

    while (rs.next()) { 

     col1 = rs.getString("col1"); 
     col2 = rs.getString("col2"); 


    } //while 
    con.close(); 
} //main 
} 

此代碼工作正常時,localEntry.sqlite文件是在我的JavaProject。在這裏,我不知道什麼是連接字符串(或任何其他方法),如果這個數據庫文件是在桌面上或在計算機上的其他地方。

回答