JDBC and MS-Access problem

做~自己de王妃 提交于 2020-01-15 10:52:25

问题


I'm trying to connect to an MSAccess database and retrieve some data. With simple examples all runs well but if i'm going to use some where clauses i get no data.

This example is ok:

PreparedStatement stm = con.prepareStatement("SELECT A.* FROM A");
ResultSet rs = stm.executeQuery();
rs.next();

The next example get no rows:

PreparedStatement stm = con.prepareStatement("SELECT A.* FROM A WHERE (((A.Name) LIKE ?))");
stm.setString(1,"*");
ResultSet rs = stm.executeQuery();
rs.next();

I don't know where the error lies: in the driver or in the sql syntax.

The sql statement is taken from the query builder in MSAccess.

All what is a little bit more complex in a where clause is a really hard to figure out. Is there any documentation reagrding sql syntax of MSAccess ?

Update

Yes in the jdbc sql statement i have to use "SQL standard" % wildcard while the Access sql builder is using *. Now going to query with dates =8-o


回答1:


For the like statement to work you have to put the parameter between %:

PreparedStatement stm = con.prepareStatement("SELECT A.* FROM A WHERE (((A.Name) LIKE ?))");
stm.setString(1,"%like text%");



回答2:


Do you, by any chance, mean the SQL wildcard character, '%', instead of '*', or are you literally looking for the character '*'?



来源:https://stackoverflow.com/questions/1795843/jdbc-and-ms-access-problem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!