(String[] args) give null on the end

Discussion in 'Plugin Development' started by TGF, Nov 2, 2012.

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

    TGF

    Hello!
    I have sth like that:
    Code:
    public void DBhandler(String[] args) {
    //some Strings over here
    //one of them is String datebase = config.getString(pathtostring);
    //and the last is String databaseURL = doesntmatter+database;
    }
    And now i use it in onEnable:
    Code:
    @Override
    public void onEnable() {
    DBhandler(null);
    }
    And here is the problem:p
    If I dont use null in DBhandler in onEnable, it doesn't work.
    If I use null in it i have a little problem because DBhandler put null as datebase in databaseURL but the rest of strings(doesntmatter) loads good.
     
  2. Offline

    cman1885

    Nobody knows what you're trying to say/do.
     
  3. Offline

    TGF

    :p Im trying to use datebase String but it return me null when loading from config.
     
  4. Offline

    cman1885

    You're sending it null..?
     
  5. Offline

    TGF

    In config.yml datebase is datebase.

    @Override
    public void onEnable() {
    DBhandler();
    }
    Doesn't work.

    @Override
    public void onEnable() {
    DBhandler(null);
    }
    Work but return me datebase as null.

    the_merciless can u help? :p
     
  6. Offline

    cman1885

    Well if you're taking a string[] you need to pass it a string[] -_-
     
  7. Offline

    fireblast709

    Then your path is probably incorrect or the path does not exist in the config
     
  8. Offline

    TGF

    fireblast709 cman1885 the_merciless i need your help! :(

    Another problem. Cannot connect to database.
    onEnable (open)
    Code:
    public void onEnable() {
            DBhandler(null);
    }

    DBhandler (open)

    Code:
    public void DBhandler(String[] args) {
            Connection connection = null;
     
            String host = config.getString("Dane.host");
            String port = config.getString("Dane.port");
            String database = config.getString("Dane.database");
            String user = config.getString("Dane.user");
            String password = config.getString("Dane.password");
     
            String postgresUrl = "jdbc:postgresql://"+host+":"+port+"/"+database;
     
                try {
                    Class.forName("org.postgresql.Driver").newInstance();
                    connection = DriverManager.getConnection(postgresUrl, user, password);
                    this.logger.info("========Connected with " + postgresUrl + " ========");
                } catch (Exception e) {
                    this.logger.info("Cannot connect with " + postgresUrl);
                }
        }
     
  9. Offline

    fireblast709

    TGF remove the try-catch and post the stacktrace. This would probably be of more help then "Cannot connect with " + postgresUrl
     
  10. Offline

    TGF

    Remove try and put new Exception().printStackTrace() as catch?

    /edit

    I found a problem, java.lang.ClassNotFoundException: org.postgresql.Driver
     
  11. Offline

    Sagacious_Zed Bukkit Docs

    Bukkit does not come prepackaged with a postgresql driver.
     
  12. Offline

    TGF

    Ok then.
    Show Spoiler
    Code:
    public void DBhandler(String[] args) {
            Connection connection = null;
       
            String host = config.getString("Dane.host");
            String port = config.getString("Dane.port");
            String database = config.getString("Dane.database");
            String user = config.getString("Dane.user");
            String password = config.getString("Dane.password");
       
            String mysql = "jdbc:mysql://";
            String UrlFormula = mysql + host + ":" + port + ";databaseName=" + database;
       
                try {
                    Class.forName("org.postgresql.Driver").newInstance();
                    connection = DriverManager.getConnection(UrlFormula, user, password);
                    this.logger.info("Connected with " + UrlFormula);
                } catch (Exception e) {
                    this.logger.info("Cannot connect with " + UrlFormula);
                    this.logger.info("ERROR:\n " + e);
                }
        }

    Version for mysql doesn't work too;/
     
  13. Offline

    TGF

    Ok solved.
    I had to add mysqlconector to the project:p
     
Thread Status:
Not open for further replies.

Share This Page