Monday, December 14, 2009

Read firefox bookmarks using Java

I've often seen people asking in various forums "how do we read firefox bookmarks from Java/C# ? ". It seemed like an interesting question and I ended up solving the question in around 2 hrs. A little bit of reading about the firefox database will be necessary. You can get that here. Now for the implementation you will need to add the jar file. You can get it here. You can add the external jar to your project and then compile the following code. The implementation only reads and lists out some fields in places.sqlite. You can modify the query and do various other things.


import java.sql.*;

public class firefoxBookmarksReader {
public static void main(String[] args) throws Exception {
Class.forName("org.sqlite.JDBC");
Connection conn = DriverManager.getConnection("jdbc:sqlite:/home/deepak/.mozilla/firefox/yvf7p20d.default/places.sqlite//"); // replace the path appropriately depending on the location of places.sqlite
if(conn==null)
{
System.out.println("ERROR");
}
System.out.println(conn.toString());

Statement stat = conn.createStatement();

ResultSet rs = stat.executeQuery("select * from moz_bookmarks;");
while (rs.next()) {
System.out.println("id = " + rs.getString("id"));
System.out.println("keyword = " + rs.getString("keyword_id"));
System.out.println("title = " + rs.getString("title"));
}
rs.close();
conn.close();
}
}


Thanks,
Layman

5 comments:

  1. 我愛那些使自己的德行成為自己的目標或命定的人..............................

    ReplyDelete
  2. and we get - Exception in thread "main" java.sql.SQLException: file is encrypted or is not a database....

    ReplyDelete
  3. Great work! I like this post and i feel very happy to read this article...
    I am very thankful to share this post.. I hope you have more information about this post.. So, Please share me.. Thanks..
    more info:- Mozilla Firefox Technical Support

    ReplyDelete