Merhabalar.
Sorum, java üzerinde sql komutunu kullanırken, komutu kabul etmiyor.
Sql komutunu ilk olarak SQL Server 2008r2 ile hazırladık. Sorgu gayet iyi bir şekilde çalışıyor. MySql üzerinde kullanacağım için MySQL Workbench üzerinde test ettim, workbench üzerinde de çalışıyor. Java projeye yazdığımda aşağıdaki hata oluşuyor.
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'COUNT(kat)>= all (select COUNT(*) from oda group by kat)' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1053)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4096)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4028)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2490)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2651)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2728)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2678)
at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1612)
at tr.edu.hmyo.keten.db._DenemeDao.test(_DenemeDao.java:17)
at tr.edu.hmyo.keten.test.Run.main(Run.java:11)
Hata oluşunca mysql-connector'un son versiyonunu indirdim. 5.1.22 ile denedim yine çalıştıramadım. Sorguyu, farklı bilgisayarda Wamp server-phpMyAdmin üzerinden denedim. phpMyAdmin üzerinde de çalıştı.
Tablo Yapısı:
create table test(id int primary key identity(1,1),kat int,odano int)
Örnek veri:
insert into test values(1,101)
insert into test values(1,102)
insert into test values(2,201)
insert into test values(2,202)
insert into test values(2,203)
insert into test values(3,301)
Sorgumuz: Örnek veriye göre sonuç 2 oluyor.
select KAT from test
group by kat
having COUNT(kat)>= all (
select COUNT(*) from test group by kat)
Sorgumuz katların hangisinde en fazla oda varsa o katı dönderiyor.
Bu hatayı nasıl düzeltebilirim veya aynı işlemi yapan farklı sql komutu yazabilir miyiz?
Şimdiden Teşekkürler.