SQLite - "Cannot use /, \ or .db " - Urgent

Discussion in 'Plugin Development' started by Unica, Feb 3, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    Unica

    Hello.


    I am trying to access a .db file.
    But I am having trouble to set the correct path.

    I read this, where he uses plugin.getDataFolder().getAbsolutePath();

    However, when I use it, I get the following error:
    Code:
    lib.PatPeter.SQLibrary.DatabaseException: The database filename cannot contain:
    /, \, or .db.
            at lib.PatPeter.SQLibrary.FilenameDatabase.setFilename(FilenameDatabase.
    java:64) ~[?:?]
            at lib.PatPeter.SQLibrary.FilenameDatabase.setFile(FilenameDatabase.java
    :90) ~[?:?]
            at lib.PatPeter.SQLibrary.FilenameDatabase.<init>(FilenameDatabase.java:
    32) ~[?:?]
            at lib.PatPeter.SQLibrary.SQLite.<init>(SQLite.java:100) ~[?:?]
            at mco.dubehh.KillsCore.tryCurrent(KillsCore.java:98) ~[?:?]
    Code:
    public int tryCurrent(Player p){
            Plugin plugin = Bukkit.getPluginManager().getPlugin(KillsRank.kitsName);
            sql = new SQLite(m.getLogger(), KillsRank.kitsName, "ScoreboardStats", plugin.getDataFolder().getAbsolutePath());
            try{
                sql.open();
                ResultSet set = sql.query("SELECT kills FROM player_stats WHERE uuid = '"+p.getUniqueId().toString()+"'");
                return set.getInt("kills");
            }catch(Exception e){
                return 0;
            }
        }
    Any thoughts?
     
  2. Offline

    Skionz

    @Unica I believe File#getAbolutePath() returns a String with such characters in it. Example: "plugins/CoolStuff/config.yml"
    As for a solution, I have no idea. I have never used SQLite before.
     
  3. Offline

    CraftCreeper6

    @Unica
    "KillsRank.java". What is kitsName?
     
  4. Offline

    Unica

  5. Offline

    CraftCreeper6

    @Unica
    So what you are doing is String.getDataFolder().getAbsolutePath();?
     
  6. Offline

    1Rogue

    I don't know what library you're using but that's a terrible exception handling. JDBC takes a typical call to the driver. From my SQLite class:

    Code:java
    1. /**
    2.   * Opens a connection to the SQLite database. Make sure to call
    3.   * {@link SQLite#close()} after you are finished working with the database
    4.   * for your segment of your code.
    5.   *
    6.   * @since 0.1.0
    7.   * @version 0.1.0
    8.   *
    9.   * @param folder A {@link File} pointing to a data folder for the database
    10.   * @param name The name of the database file
    11.   * @return The Connection object
    12.   * @throws SQLException If the connection fails to open
    13.   */
    14. public Connection open(File folder, String name) throws SQLException {
    15. if (folder == null || !folder.exists() || !folder.isDirectory()) {
    16. throw new IllegalArgumentException("Folder must be a non-null, existing directory!");
    17. }
    18. try {
    19. Class.forName("org.sqlite.JDBC");
    20. } catch (ClassNotFoundException ex) {
    21. Debugger.error(ex, "Error loading SQLite drivers!");
    22. }
    23. this.con = DriverManager.getConnection("jdbc:sqlite:" + folder.getAbsolutePath() + File.separatorChar + name + ".db");
    24. Debugger.print("Open SQLite connections: %d", ++connections);
    25. return this.con;
    26. }
     
Thread Status:
Not open for further replies.

Share This Page