NullPointerException in SQLServerDatabaseMetaData

Con risposta NullPointerException in SQLServerDatabaseMetaData

  • sabato 28 aprile 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

Tutte le risposte

  • domenica 29 aprile 2012 08:40
    Moderatore
     
     

    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.

  • domenica 29 aprile 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.
  • domenica 29 aprile 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.


    • Modificato sproketboy lunedì 30 aprile 2012 11:19 remove smarm
    •  
  • lunedì 30 aprile 2012 03:23
    Moderatore
     
     Risposta suggerita

    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

  • lunedì 30 aprile 2012 11:20
     
     Con risposta
    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.