빠른 설명을 드리겠습니다. 저는 7 월에 자바 회사를 통해 5 주 과정을 밟았습니다. 그것들은 콘솔 응용 프로그램, crud 작업, mysql 및 n 계층 아키텍처와 같은 기본적인 것들을 다루었습니다. 코스가 끝난 이후로 나는 일하러 돌아 갔고 다른 의학적 이유가 떠올랐다.내 검색 방법이 모두 null로 설정됩니다.
나는 회사에서 배운 것을 반영 할 수있는 간단한 프로그램을 만들라는 말을 들었습니다. 내가 거의 유지하지 못했다.
나는 비디오 게임 스타지 프로그램을 만들기로 결정했습니다. 책장을 검색 할 필요가 없도록 비디오 게임을 응시하는 데 사용됩니다.
MYSQL에서의 crud 작업을 사용하는 기본 콘솔 앱입니다. 실제로 검색 기능을 사용할 수 없습니다. 프리젠 테이션 레이어와 로직 레이어의 두 레이어가 있습니다. 검색 방법을 사용하면 제목으로 게임을 검색 할 수 있습니다. 내가 프로그램을 실행하고 검색을 사용하면 제목 만 표시되고 나머지는 null입니다. 여기 내 프리젠 테이션 계층입니다 :
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
어떤 도움을 크게 감상 할 수 있으며 사전에 감사합니다
편집 : 여기 당신은 당신도 제목을 설정하지 않고 getTitle()
를 사용, 새로운 Games
객체를 생성 내 게임 클래스
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;
}
} SearchGame()
에서
나는 응용 프로그램을 디버깅하려고합니다. 'rs.getInt ("GameId")'는 무엇을 반환합니까? 데이터베이스에 데이터가 있습니까? – JLe
그래, 내 테이블에 적어도 4 행이있다 –
그리고 그들은 다른 필드에 대한 데이터가 포함되어 있습니까? 'Games' 클래스의 코드도 게시 할 수 있습니까? – JLe