SQLite Access Denied

Discussion in 'Plugin Development' started by caseif, Aug 17, 2012.

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

    caseif

    I've been working on a plugin that uses SQLite to store information, and I keep getting the error:

    [SEVERE] java.sql.SQLExcetion: opening db: 'D:\PvP_KDR': Access is denied

    My code uses this line to connect:

    Code:java
    1. conn = DriverManager.getConnection(jdbc:sqlite:D:\\PvP_KDR");


    This is the first time I've used SQLite, so I have no idea what I'm doing. How do I fix this?
     
  2. Offline

    Giant

    That is not a database but a directory, hence why it denies access. I suggest using something among the lines of:
    Code:
    String dbPath = "jdbc:sqlite:" + plugin.getDir() + plugin.getSeparator() + "database.db";
    this.con = DriverManager.getConnection(dbPath);
    
    What this does is the following, it creates a var holding the database path, which in this case would be plugins/[myplugin][/ or\ depending on system]database.db hope that helps! :)
     
  3. Offline

    caseif

    Eclipse is giving me an error on both "plugin"s, saying it cannot be resolved. What should I do about that?
     
  4. Offline

    toothplck1

    You need to make Plugin plugin a variable and initialize it. If this is in your main class just change them to "this"
     
  5. Offline

    caseif

    I'm not quite sure how to initialize a Plugin variable, and since I'm in my main class, I tried replacing them with "this". Now it's giving me errors on "getDir()" and getSeparator()", saying that they're undefined for the type PvP_KDR (name of my main class).

    EDIT: I fixed the error on "getDir()" by changing it to "getDataFolder()", but I'm still trying to figure out how to fix the error on "getSeparator()".
     
  6. Offline

    Giant

    Uhh woops, my mistake on those, the code I placed above comes right out of my own database driver system (really cool one, build it myself, doesn't even need you to know sql at all either :))
    But, getDir() returns getDataFolder() as you already figured out! And getSeperator() could actually be replaced with File.seperator as that is what it returns. Sorry for that inconvience I caused you there :(
     
  7. Offline

    caseif

    Thanks. It seems to have fixed the problem; I'll try compiling it now.
     
Thread Status:
Not open for further replies.

Share This Page