2 Replies Latest reply on Feb 20, 2013 7:56 PM by jschellSomeoneStoleMyAlias

    Jdbc connection mssql empty URL


      Hello i've got this code:

      DatabaseManager.init("com.inet.tds.TdsDriver", "jdbc:inetdae:", "username", "password", 10);

      which links to:

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

      URL = parURL;
      userName = parUserName;
      passWord = parPassWord;

      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
          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
            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.