关于mysql模糊查询问题,急!急!急!
最近,小弟用到mysql模糊查询时碰到了一个难以解决的问题,在网上找了很多了资料,也没能解决,希望在这里碰到高手,帮小弟度过难关,小弟我感激涕零~~~
好的,看下面这段代码吧:
SQL code:
mysql> use mingxuan;
Database changed
mysql> select count(id) from product where ptype like '%联想%' and bid=(
-> select id from brand where bname='联想' and cid=(
-> select id from category where id=4
-> )
-> );
+-----------+
| count(id) |
+-----------+
| 2 |
+-----------+
1 row in set (0.00 sec)
在mysql里面可以用这个sql语句进行模糊查询,但是到了Java程序里面用con.prepareStatement(sql);问题就来了
代码如下:
Java code:
String sql = "select count(id) from product "
+ "where ptype like ? and bid=( "
+ "select id from brand where bname=? and cid=( "
+ "select id from category where id=?));";
con = DBUtil.getConnect();
try {
ps = con.prepareStatement(sql);
ps.setString(1, "%" + type + "%");
ps.setString(2, bname);
ps.setInt(3, cid);
rs = ps.executeQuery();
if (rs.next()) {
相关问答:
在安装Java编译器的Eclipse的时候,对环境变量进行了配置,在安装MySQl的时候也要对环境变量进行配置;那么后面的配置会影响前面的Eclipse的配置吗?
请大家多指教~!谢谢!
不会把,我这都装了的 我系统里 还装了 ......
先上错误
无法联接数据库
java.sql.SQLException: Before start of result set
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:910)
at com.mysql.jdbc.ResultSet.checkRowPos(ResultSet.java: ......
我已经按照教程上配置tomcat的server.xml
<Context path = "/POS" docBase = "POS" debug = "5" reloadable = "true" crossContext = "true" workDir = &quo ......
CREATE DATABASE ADDRESSLIST;
USE ADDRESSLIST;
DROP TABLE IF EXISTS FRIEND;
CREATE TABLE FRIEND
(FRIEND_ID INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY ,
FRIEND_NAME VARCHAR(20) NOT N ......
在C++程序中通过mysql的C API直接连接数据库,当把中文插入mysql的时候,就变成乱码了.
还有就是使用load把文本文件导入mysql数据库,无论文本文件是ANSI编码还是utf8编码,导入之后都是乱码。
其中mysq的编码格式 ......