我正在使用MySQL和JDBC将数据库用于JSP中的站点。查询适用于phpMyAdmin,但不适用于Java
我为搜索命令生成一个SQL查询,当我在phpMyAdmin上手动运行该查询并且它返回1行匹配时,查询起作用。
但执行我的查询后,ResultSet是空的(我无法获得表的值)。
这是执行查询的代码:
:SELECT * FROM产品WHERE个prodName LIKE '%מהיר%' AND存在= 1
public static Product findLikeProd(String ProductName)
{
Product Product = null;
try
{
ResultSet rs = Database.executeSelect1("SELECT * FROM products WHERE prodName LIKE '%"+ProductName+"%' AND exist=1");
if (rs.next())
{
Product = new Product(rs.getInt("PKid"), rs.getString("prodName"), rs.getString("description"), rs.getDouble("price"), rs.getInt("deliveryTime"), rs.getString("imgUrl"));
}
//Database.closeCon();
}
catch (SQLException e)
{
e.printStackTrace();
}
return Product;
}
例如查询
该代码:
public synchronized static ResultSet executeSelect1(String sqlCmd) {
ResultSet rs = null;
try {
MysqlDataSource ds = new MysqlConnectionPoolDataSource();
ds.setServerName("localhost");
ds.setDatabaseName("tarazJsp");
con=ds.getConnection("root","");
Statement st = con.createStatement();
rs = st.executeQuery(sqlCmd); //The problem is here. rs is received(!=null) but I can't get his parameters.(empty)
} catch (SQLException e) {
e.printStackTrace();
}
return rs;
}
当我尝试从rs获取字符串时,它会引发SQLException。
我该如何解决?
什么是SQL查询的重复? –
您已发布两个(几乎)相同/重复的问题。删除他们不污染SO – informatik01
尝试[这个答案](http://stackoverflow.com/questions/14738732/mysql-does-not-store-properly-some-utf8-chars/14738790#14738790) – Eran