Solved java.sql.SQLException: The url cannot be null

Discussion in 'Plugin Development' started by skipperguy12, Nov 23, 2012.

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

    skipperguy12

    ------------------------------------------------


    SOLVED :D Thanks to fireblast709


    ------------------------------------------------
    That? My URL isn't null...

    I've got a config which looks like this:

    Code:
    Config:
      MySQL:
        URL:
          IP: SQL09.FREEMYSQL.NET
          PORT: '3306'
          DATABASE: ***(I know its correct)
        Password: **** (I know its correct)
        Username: ***** (I know its correct)
    
    *Note, the URL is just a list, IP is the actual URL.
    Heres my code:


    Code:
    public void CreateMainTable() throws SQLException {
              try {
                Class.forName("com.mysql.jdbc.Driver");
            } catch (ClassNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
       
              Connection conn = DriverManager.getConnection(url, user, pass);
            DatabaseMetaData dbm = conn.getMetaData();
     
            ResultSet tables = dbm.getTables(null, null, "sgteams", null);
     
     
     
            System.out.println("Checking for sgteams database table....");
            if (!tables.next()) {
                System.out.println("Table not found, creating table");
              Statement stmt = conn.createStatement();
              String sql = "CREATE TABLE sgteams(id INT AUTO_INCREMENT KEY, player VARCHAR(50),totalkills INT, totaldeaths INT, score INT, donortype VARCHAR(50))";
              stmt.executeUpdate(sql);
            }
            conn.close(); }
    Its called in onEnable using this:
    Code:
     public void CreateTables() {
     
              try {
                CreateMainTable();
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
     
     
     
          }
    EDIT:

    All my imports are java.sql also
     
  2. Offline

    chaseoes

    We need your full code. The sections you provided don't help in solving the problem.
     
  3. Offline

    skipperguy12

    Well, why? I give you all the SQL parts of the plugin, tell you where thy are called, and also tell ou how the on fig looks and works... The entire code is huge, and private. Tell me what other parts of the code you need.
     
  4. Offline

    fireblast709

    like... the creation and definition of 'url' might be useful, it is null for a reason ;D
     
  5. Offline

    skipperguy12

    I inserted all my data directly, just to test it (without config) same error.
    Code:
    url = "jdbc:mysql://SQL09.FREEMYSQL.NET:3306/[DATABASE]";
                //pass = this.getConfig().getString("Config.MySQL.Password");
                //user = this.getConfig().getString("Config.MySQL.Username");
                pass = this.getConfig().getString("[USER]");
                user = this.getConfig().getString("[PASS]");
    Url, pass, and user are just defined at the top of the code, they are Public strings:

    public String url;
    public String pass;
    public String user;

    This is a bit how my onEnable goes:
    Code:
    public void onEnable() {
           
     
            final File file = new File(getDataFolder() + File.separator
                    + "config.yml");
     
            if (!file.exists()) {
                this.getLogger().info("Generating config files for Sgteams");
       
     
                getConfig().addDefault("Config.MySQL.URL.IP", "LOCALHOST");
     
                getConfig().addDefault("Config.MySQL.URL.PORT", "3306");
     
                getConfig().addDefault("Config.MySQL.URL.DATABASE", "DATABASE");
     
                getConfig().addDefault("Config.MySQL.Password", "Password");
     
                getConfig().addDefault("Config.MySQL.Username", "username");
     
                this.getConfig().options().copyDefaults(true);
     
                this.saveConfig();
     
                //url = "jdbc:mysql://"
                //        + this.getConfig().getString("Config.MySQL.URL.IP") + ":"
                //        + this.getConfig().getString("Config.MySQL.URL.PORT") + "/"
                //        + this.getConfig().getString("Config.MySQL.URL.DATABASE");
               
                url = "jdbc:mysql://SQL09.FREEMYSQL.NET:3306/hawkeyesqldb";
                pass = this.getConfig().getString("Config.MySQL.Password");
                user = this.getConfig().getString("Config.MySQL.Username");
     
            }
            CreateTables();
        }
    
     
  6. Offline

    fireblast709

    And what is the full stacktrace?
     
    skipperguy12 likes this.
  7. Offline

    skipperguy12

    Code:
    2012-11-24 08:48:27 [INFO] SGTeams version 2.0 is enabled!
    2012-11-24 08:48:27 [SEVERE] java.sql.SQLException: The url cannot be null
    2012-11-24 08:48:27 [SEVERE]    at java.sql.DriverManager.getConnection(Unknown
    Source)
    2012-11-24 08:48:27 [SEVERE]    at java.sql.DriverManager.getConnection(Unknown
    Source)
    2012-11-24 08:48:27 [SEVERE]    at com.github.skipperguy12.SGTeams.SGTeams.Creat
    eMainTable(SGTeams.java:147)
    2012-11-24 08:48:27 [SEVERE]    at com.github.skipperguy12.SGTeams.SGTeams.Creat
    eTables(SGTeams.java:131)
    2012-11-24 08:48:27 [SEVERE]    at com.github.skipperguy12.SGTeams.SGTeams.onEna
    ble(SGTeams.java:125)
    2012-11-24 08:48:27 [SEVERE]    at org.bukkit.plugin.java.JavaPlugin.setEnabled(
    JavaPlugin.java:217)
    2012-11-24 08:48:27 [SEVERE]    at org.bukkit.plugin.java.JavaPluginLoader.enabl
    ePlugin(JavaPluginLoader.java:374)
    2012-11-24 08:48:27 [SEVERE]    at org.bukkit.plugin.SimplePluginManager.enableP
    lugin(SimplePluginManager.java:381)
    2012-11-24 08:48:27 [SEVERE]    at org.bukkit.craftbukkit.CraftServer.loadPlugin
    (CraftServer.java:270)
    2012-11-24 08:48:27 [SEVERE]    at org.bukkit.craftbukkit.CraftServer.enablePlug
    ins(CraftServer.java:252)
    2012-11-24 08:48:27 [SEVERE]    at org.bukkit.craftbukkit.CraftServer.reload(Cra
    ftServer.java:579)
    2012-11-24 08:48:27 [SEVERE]    at org.bukkit.Bukkit.reload(Bukkit.java:183)
    2012-11-24 08:48:27 [SEVERE]    at org.bukkit.command.defaults.ReloadCommand.exe
    cute(ReloadCommand.java:22)
    2012-11-24 08:48:27 [SEVERE]    at org.bukkit.command.SimpleCommandMap.dispatch(
    SimpleCommandMap.java:185)
    2012-11-24 08:48:27 [SEVERE]    at org.bukkit.craftbukkit.CraftServer.dispatchCo
    mmand(CraftServer.java:502)
    2012-11-24 08:48:27 [SEVERE]    at org.bukkit.craftbukkit.CraftServer.dispatchSe
    rverCommand(CraftServer.java:494)
    2012-11-24 08:48:27 [SEVERE]    at net.minecraft.server.DedicatedServer.al(Dedic
    atedServer.java:258)
    2012-11-24 08:48:27 [SEVERE]    at net.minecraft.server.DedicatedServer.r(Dedica
    tedServer.java:223)
    2012-11-24 08:48:27 [SEVERE]    at net.minecraft.server.MinecraftServer.q(Minecr
    aftServer.java:493)
    2012-11-24 08:48:27 [SEVERE]    at net.minecraft.server.MinecraftServer.run(Mine
    craftServer.java:426)
    2012-11-24 08:48:27 [SEVERE]    at net.minecraft.server.ThreadServerApplication.
    run(SourceFile:856)
     
  8. Offline

    fireblast709

    Code:java
    1. public void onEnable()
    2. {
    3. final File file = new File(getDataFolder() + File.separator
    4. + "config.yml");
    5.  
    6. if (!file.exists()) {
    7. this.getLogger().info("Generating config files for Sgteams");
    8.  
    9.  
    10. getConfig().addDefault("Config.MySQL.URL.IP", "LOCALHOST");
    11.  
    12. getConfig().addDefault("Config.MySQL.URL.PORT", "3306");
    13.  
    14. getConfig().addDefault("Config.MySQL.URL.DATABASE", "DATABASE");
    15.  
    16. getConfig().addDefault("Config.MySQL.Password", "Password");
    17.  
    18. getConfig().addDefault("Config.MySQL.Username", "username");
    19.  
    20. this.getConfig().options().copyDefaults(true);
    21.  
    22. this.saveConfig();
    23. }
    24.  
    25. //url = "jdbc:mysql://"
    26. // + this.getConfig().getString("Config.MySQL.URL.IP") + ":"
    27. // + this.getConfig().getString("Config.MySQL.URL.PORT") + "/"
    28. // + this.getConfig().getString("Config.MySQL.URL.DATABASE");
    29.  
    30. url = "jdbc:mysql://SQL09.FREEMYSQL.NET:3306/hawkeyesqldb";
    31. pass = this.getConfig().getString("Config.MySQL.Password");
    32. user = this.getConfig().getString("Config.MySQL.Username");
    33.  
    34. CreateTables();
    35. }

    You were defining the url inside the !file.exists()
     
    skipperguy12 likes this.
  9. Offline

    skipperguy12

    *FACEDESK*

    THANK YOU!
    :D
     
Thread Status:
Not open for further replies.

Share This Page