NullPointerException in SQLServerDatabaseMetaData

Answered NullPointerException in SQLServerDatabaseMetaData

  • sábado, 28 de abril de 2012 21:05
     
     

    Hi all,

    I get the following error when trying retrive the table names from a connection.


    java.lang.NullPointerException
     at com.microsoft.sqlserver.jdbc.SQLServerDatabaseMetaData.getResultSetWithProvidedColumnNames(SQLServerDatabaseMetaData.java:308)
     at com.microsoft.sqlserver.jdbc.SQLServerDatabaseMetaData.getTables(SQLServerDatabaseMetaData.java:466)

    I'm calling the method like this:

    String[] tableTypes = {"TABLE"};
    rs = con.getMetaData().getTables(null, null, null, tableTypes);

    I downloaded the latest MSSQL JDBC Driver (Microsoft JDBC Driver 4.0 for SQL Server) and I'm running under Java 6 with the sqljdbc4.jar library.

    Any ideas?

    TIA

Todas as Respostas

  • domingo, 29 de abril de 2012 08:40
    Moderador
     
     

    Hello,

    I am far to be a specialist of java but i am surprised by the way you are loading the tableTypes string array. I would try null as value as you want informations about all the tables.

    http://msdn.microsoft.com/en-us/library/ms378769.aspx

    i saw "An array of strings that contain the types of tables to include. Null indicates that all types of tables should be included" for the last parameter.

    Have a nice day


    Mark Post as helpful if it provides any help.Otherwise,leave it as it is.

  • domingo, 29 de abril de 2012 17:51
     
     
    It seems that it requires '%' for the schema pattern parameter. Not sure why - it's not mentioned in the docs I could find.
  • domingo, 29 de abril de 2012 17:53
     
     

    That's causing : 

    ERROR Apr 29 13:52:53 net.sf.pinf.TestMSSQL - Software caused connection abort: recv failed
    com.microsoft.sqlserver.jdbc.SQLServerException: Software caused connection abort: recv failed
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.java:1667) ~[sqljdbc4.jar:na]

    It works fine with JTDS.


    • Editado sproketboy segunda-feira, 30 de abril de 2012 11:19 remove smarm
    •  
  • segunda-feira, 30 de abril de 2012 03:23
    Moderador
     
     Resposta Proposta

    Hi sproketboy,

    Please pay attention to this similar thread to return table names: How to get all table names from a database? 

    I think it is more about the usage of the
    getTables function in Java, you may ask a question on Java forum for better assistance if you need more information.

    TechNet Subscriber Support
    If you are TechNet Subscription user and have any feedback on our support quality, please send your feedback here.


    Stephanie Lv

    TechNet Community Support

  • segunda-feira, 30 de abril de 2012 11:20
     
     Respondido
    Thanks. I realized this seems to be an issue with running on the same machine. When I try it on a different machine it works fine.