problem with SQLite

Discussion in 'Plugin Development' started by geert305, Apr 12, 2014.

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

    geert305

    I am a beginning developer but I can't create a SQLite db in the plugins folder with this code. I tried many things but no result.

    This is my code:

    Code:java
    1. package me.Geert305.Plugin;
    2.  
    3.  
    4. import java.sql.Connection;
    5. import java.sql.DriverManager;
    6. import java.sql.ResultSet;
    7. import java.sql.SQLException;
    8. import java.sql.Statement;
    9. import java.util.logging.Logger;
    10.  
    11. import lib.PatPeter.SQLibrary.SQLite;
    12.  
    13. import org.bukkit.Bukkit;
    14. import org.bukkit.craftbukkit.libs.jline.internal.Log;
    15. import org.bukkit.plugin.Plugin;
    16. import org.bukkit.plugin.PluginBase;
    17. import org.bukkit.plugin.PluginLogger;
    18. import org.bukkit.plugin.PluginManager;
    19. import org.bukkit.plugin.java.JavaPlugin;
    20.  
    21.  
    22.  
    23.  
    24. public class Mai extends JavaPlugin {
    25.  
    26. @Override
    27. public void onEnable(){
    28. PluginManager manager = this.getServer().getPluginManager();
    29.  
    30. Connection c = null;
    31. try {
    32. Class.forName("org.sqlite.JDBC");
    33.  
    34. c = DriverManager.getConnection("jdbc:sqlite:" + getServer().getPluginManager().getPlugin("DeDiamond").getDataFolder().toPath().toString() + "/data.db");
    35. Statement stmt = c.createStatement();
    36. stmt.executeUpdate("CREATE TABLE IF NOT EXISTS `homes` (`home_naam` varchar(20) NOT NULL,`speler` varchar(20) NOT NULL,`wereld` varchar(20) NOT NULL, `locatiex` int(11) NOT NULL,`locatiey` int(11) NOT NULL,`locatiez` int(11) NOT NULL,KEY `home_naam` (`home_naam`,`speler`))");
    37. } catch ( Exception e ) {
    38. System.out.println(e);
    39. }
    40.  
    41.  
    42.  
    43. manager.registerEvents(new TNTlistener(), this);
    44.  
    45. this.getCommand("diajoin").setExecutor(new PlayerComm());
    46. //this.getCommand("maakhome").setExecutor(new NieuwHome());
    47. //this.getCommand("gahome").setExecutor(new GaHome());
    48. }
    49. public void onDisable() {
    50.  
    51. }
    52.  
    53.  
    54. }
     
  2. Offline

    Timbo_KZ

    geert305
    Can you post your error code? I'm sure SQLite generates a SQLException if something goes wrong.
     
  3. Offline

    blablubbabc

    You probably might have to create the database file yourself before you can use it with sqlite.
     
  4. Offline

    epicfacecreeper

    Why are you importing SQLibrary and then using JDBC?
     
Thread Status:
Not open for further replies.

Share This Page