hai all, I am writing an application where I am using JDBC to connect to access database. I am using the DSN to connect to the Database. I use the method createStatement() to create a statement object thro which I get a resultset by passing a query to the executeQuery() method. Whenever I give a simple query everything works fine but when I give a complex query like the one below I just get a error. The Error that I get is java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1. at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6106) at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:6263) ---- rest ignored --- SELECT DISTINCTROW Orders.ShipName, Orders.ShipAddress, Orders.ShipCity, Orders.ShipRegion, Orders.ShipPostalCode, Orders.ShipCountry, Orders.CustomerID, Customers.CompanyName, Customers.Address, Customers.City, Customers.Region, Customers.PostalCode, Customers.Country, [FirstName] & " " & [LastName] AS Salesperson, Orders.OrderID, Orders.OrderDate, Orders.RequiredDate, Orders.ShippedDate, Shippers.CompanyName, [Order Details].ProductID, Products.ProductName, [Order Details].UnitPrice, [Order Details].Quantity, [Order Details].Discount, CCur([Order Details].[UnitPrice]*[Quantity]*(1-[Discount])/100)*100 AS ExtendedPrice, Orders.Freight FROM Shippers INNER JOIN (Products INNER JOIN ((Employees INNER JOIN (Customers INNER JOIN Orders ON Customers.CustomerID = Orders.CustomerID) ON Employees.EmployeeID = Orders.EmployeeID) INNER JOIN [Order Details] ON Orders.OrderID = [Order Details].OrderID) ON Products.ProductID = [Order Details].ProductID) ON Shippers.ShipperID = Orders.ShipVia; The how to execute the complex queries like the one above in java. Even my application hangs when I give a cartesion query. please help... thanking you, L.Sivaraman.
I feel the error is due to passing invalid number of parameters to the SQL querry. Please check the query directly thru MS-Access database interface. I suggest it's better to use PreparedStatement instead of simple Statement when we need to execute Complex queries.
Usually this error message occurs if you spell a column or table name wrong in your query. Cut and paste it into the Access SQL editor to execute, it'll give you an error message that actually might make sense. Good old Microsoft! Jamie
posted 15 years ago
hai all, As u said i tried this query in MSAccess. it work fine. but only when i send this query to my app, an exception is thrown help me pl thanks sivaraman.
I hope you don't include the semi-colon at the end of your sql statement in your java sql string? String sql = "SELECT DISTINCTROW Orders.... ON Shippers.ShipperID = Orders.ShipVia;"; //the inner semi-colon would be bad!! Jamie