2 Replies Latest reply: Feb 20, 2013 1:56 PM by jschellSomeoneStoleMyAlias RSS

    Jdbc connection mssql empty URL

    991547

      Hello i've got this code:

      DatabaseManager.init("com.inet.tds.TdsDriver", "jdbc:inetdae:127.0.0.1?database=main", "username", "password", 10);

      which links to:

      public static void init(String JDBCDriver, String parURL, String parUserName, String parPassWord, int maxConnections) throws ClassNotFoundException, SQLException {

      Class.forName(JDBCDriver);
      URL = parURL;
      userName = parUserName;
      passWord = parPassWord;
      openConnection();
      }

      But gives me this fault:

      DatabaseManager.getConnection() : java.sql.SQLException: The url cannot be null

      By this script:

      public static void openConnection() throws SQLException{     connection = DriverManager.getConnection(URL, userName, passWord); } public static Connection getConnection() {     try {         if (connection!=null) {             if (connection.isClosed())                 openConnection();         }         else {             openConnection();         }     } catch (SQLException e) {             System.out.println("DatabaseManager.getConnection() : " + e);            return null;     }     return connection; Does anyone have any idea why it tells me the url is empty? Please let me know if you need to see more scripting                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
        • 1. Re: Jdbc connection mssql empty URL
          gimbal2
          Its not scripting - you compile the code into a binary format and you execute that. You should make sure to use proper terminology to avoid confusion.

          Don't post snippets, post the entire class (you can leave out the import statements though). And use \
           tags to make it readable.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
          • 2. Re: Jdbc connection mssql empty URL
            jschellSomeoneStoleMyAlias
            988544 wrote:
            But gives me this fault:

            DatabaseManager._getConnection()_ : java.sql.SQLException: The url cannot be null

            By this script:
            public static void openConnection() throws SQLException{
            
            connection = DriverManager._getConnection(URL, userName, passWord);_
            }
            
            public static Connection _getConnection()_ {
            One of those things is not like the other.

            I suggest that you print the stack trace instead of just printing the message.