I have a problem with SQL Server JDBC driver, I tried the Microsoft JDBC driver and also the JTDS driver, but they have both the same problem: in the ResultSet if I look for "table.field" I get the error "invalid column name", but if I look for "field" only it works. This is a problem for me, because I have an application that automatically generates queries and uses the notation "table.field", for now I have worked on MySQL and Postgresql and it worked fine, but now I need to add SQL Server support and I have found this problem. It's a problem of misconfiguration of the driver or they work only in this way? There are other drivers available?
I also found a case that I can't make work, for example I created two tables with a field with the same name, and I made the cartesian product between them.
The tables t1,t2 are identical and they have this structure
------
| id |
------
| 1 |
------
| 2 |
------
If I execute the query
SELECT * FROM t1,t2
on SQL Server the result will be
-----------
| id | id |
-----------
| 1 | 1 |
-----------
| 1 | 2 |
-----------
| 2 | 1 |
-----------
| 2 | 2 |
-----------
But from Java using the JDBC driver I can't obtain the same result, because I cannot access to t1.id, t2.id but only to id and it returns only the first column.
Here's the sample code
Connection conn = DriverManager.getConnection("jdbc:jtds:sqlserver://localhost:1433/test", "user", "pass");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM t1, t2");
while(rs.next()){
System.out.println(rs.getString("id")); //This works
System.out.println(rs.getString("t1.id"));//This not works
}