这是我按下可运行程序时的代码,我什么也没收到(已连接)我想展示名称包含“ DM”的玩具]
import java.sql.*;
public class Toy {
public static void main(String args[]) throws Exception {
String query = "SELECT ToyName, Price, color from Toy WHERE ToyName='DM '";
System.out.println("concected");
Connection c=DriverManager.getConnection("jdbc:ucanaccess://C:\\Users\\96650\\Documents\\toy.accdb");
Statement stmt = c.createStatement();
ResultSet rs = stmt.executeQuery(query);
while(rs.next()) {
String desc = rs.getString("ToyName");
String color = rs.getString("Color");
double price=rs.getDouble("Price");
System.out.println(desc+" Color: "+color+"\n $"+price);}}}
我认为您的SQL查询是错误的。当前查询将选择toyName == 'DM '
至最的玩具,我想这不是您想要的。
要获取所有名称包含'DM'的玩具,您需要使用LIKE
,因此将您的sql查询更新为这样:
String query = "SELECT ToyName, Price, color from Toy WHERE ToyName LIKE '%DM%'";