让我给一个快速解释。我在7月份通过一家Java公司参加了为期5周的课程。他们涵盖了基本的东西,如控制台应用程序,crud操作,mysql和n层体系结构。自从课程结束后,我没有多用它,因为我回去工作了,其他医学原因浮出水面......等等等等。我的搜索方法是想出所有的空值
该公司告诉我做一个简单的程序来反映我学到的东西。原来我保留得很少。
我决定制作一个视频游戏的计划。 (你永远保存您的游戏或如何)。它将被用来盯着你的视频游戏,所以你就不必寻找你的书柜
是使用了与MYSQL CRUD操作一个基本的控制台应用程序。我无法让我的搜索功能实际工作。我有2层一个表示层和一个逻辑层。搜索方法允许他们通过标题搜索游戏。当我运行该程序并使用搜索它只显示标题,其余为空。 这里是我的表示层:
private static Games SearchForGame()
{
Logic aref = new Logic();
Games g = new Games();
Scanner scanline = new Scanner(System.in);
System.out.println("Please enter the name of the game you wish to find:");
g.setTitle(scanline.nextLine());
aref.SearchGame();
System.out.println();
System.out.println("Game Id: " + g.getGameId());
System.out.println("Title: " + g.getTitle());
System.out.println("Rating: " + g.getRating());
System.out.println("Platform: "+ g.getPlatform());
System.out.println("Developer: "+ g.getDeveloper());
return g;
}
,这里是我的逻辑层
public Games SearchGame() {
Games g = new Games();
try {
Class.forName(driver).newInstance();
Connection conn = DriverManager.getConnection(url+dbName,userName,password);
java.sql.PreparedStatement statement = conn.prepareStatement("SELECT GameId,Title,Rating,Platform,Developer FROM games WHERE Title=?");
statement.setString(1, g.getTitle());
ResultSet rs = statement.executeQuery();
while(rs.next()){
g.setGameId(rs.getInt("GameId"));
g.setTitle(rs.getString("Title"));
g.setRating(rs.getString("Rating"));
g.setPlatform(rs.getString("Platform"));
g.setDeveloper(rs.getString("Developer"));
statement.executeUpdate();
}
} catch (Exception e) {
e.printStackTrace();
}
return g;
}
这里也是我的最后结果
Please enter the name of the game you wish to find:
Skyrim
Game Id: 0
Title: Skyrim
Rating: null
Platform: null
Developer: null
任何帮助,将不胜感激和感谢提前
编辑:这是我为我的游戏课
public class Games
{
public int GameId;
public String Title;
public String Rating;
public String Platform;
public String Developer;
public int getGameId()
{
return GameId;
}
public int setGameId(int gameId)
{
return GameId = gameId;
}
public String getTitle()
{
return Title;
}
public String setTitle(String title)
{
return Title = title;
}
public String getRating()
{
return Rating;
}
public void setRating(String rating)
{
Rating = rating;
}
public String getPlatform()
{
return Platform;
}
public void setPlatform(String platform)
{
Platform = platform;
}
public String getDeveloper()
{
return Developer;
}
public void setDeveloper(String developer)
{
Developer = developer;
}
}
我想尝试调试应用程序。 'rs.getInt(“GameId”)'返回什么?数据库中是否有数据? – JLe
是的,我的表格中至少有4行 –
它们包含其他字段的数据吗?你可以发布“游戏”类的代码吗? – JLe