JDBC和MS-Access问题 [英] JDBC and MS-Access problem

查看:109
本文介绍了JDBC和MS-Access问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试连接到MSAccess数据库并检索一些数据. 通过简单的示例,一切运行良好,但是如果我要使用一些示例 我的where子句没有数据.

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.

这个例子还可以:

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

下一个示例不显示行:

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

我不知道错误在哪里:在驱动程序中还是在sql语法中.

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

该sql语句来自MSAccess中的查询生成器.

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

where子句中所有稍微复杂的东西真的很难弄清楚.是否有任何有关MSAccess的sql语法的文档?

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 ?

更新

是的,在jdbc sql语句中,当Access sql构建器使用*时,我必须使用"SQL standard"%通配符.现在要查询日期= 8-o

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

推荐答案

为使like语句起作用,您必须将参数放在%之间:

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%");

这篇关于JDBC和MS-Access问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆