I am using Netbeans 6.0 with Microsoft SQL 2005 and having trouble executing parameterised queries.
I tried both Microsoft�s JDBC and JTDS and both of them behave the same. I design the query in query editor and when I run the query in the query editor, it runs OK if I do not give any parameters. But If I specify a parameter, it gives error (after I enter the parameter in the pop-up window). Please also note that the query also fails in the actual program. Below is a sample basic query that does not work:
SELECT ALL dbo.Contacts.ContactID, dbo.Contacts.Display FROM dbo.Contacts WHERE dbo.Contacts.ContactID = ?
However, If I specify the query as:
SELECT ALL dbo.Contacts.ContactID, dbo.Contacts.Display FROM dbo.Contacts WHERE dbo.Contacts.ContactID = 3
It runs OK.
The error messages I get are (with two different drivers):
jtds-1.2.2: Unable to convert value to NULL
sqljdbc_1.2: com.microsoft.sqlserver.jdbc.SQLServerException:There is no metadata.
The same query runs successfully in SQL 2005 Management Studio Query Editor is:
SELECT ContactID, Display FROM Contacts WHERE (ContactID = @Param1)
If I use the default database (Travel) and the driver (Derby) comes in Netbeans, the parameterised query below also runs successfully:
SELECT ALL TRAVEL.PERSON.PERSONID, TRAVEL.PERSON.NAME FROM TRAVEL.PERSON WHERE TRAVEL.PERSON.PERSONID = ?