我正在使用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