my Search method is coming up with all nulls
Posted
by
Epic.Distortion
on Stack Overflow
See other posts from Stack Overflow
or by Epic.Distortion
Published on 2013-10-25T21:09:17Z
Indexed on
2013/10/25
21:54 UTC
Read the original article
Hit count: 127
Let me give a quick explanation. I took a 5 week course through a company on Java in July. They covered basic stuff, like console app, crud operations, mysql, and n-tier architecture. Since the course ended I didn't use it much because I went back to work, and other medical reasons surfaced....blah blah.
I was told by the company to make a simple program to reflect what I learned. Turns out I retained very little.
I decided to make a video game starage program. It would be used to stare your video games so you wouldn't have to search your bookcase(or how ever you store your games.)
It is a basic console app using the crud operations with MYSQL. I can't get my search function to actually work. I have 2 layers a Presentation layer and a Logic layer. The search method allows them to search for a game by the title. when i bring run the program and use Search it only displays the title and the rest is null. here is my Presentation layer:
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;
}
and here is my logic layer
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;
}
here is also my last results
Please enter the name of the game you wish to find:
Skyrim
Game Id: 0
Title: Skyrim
Rating: null
Platform: null
Developer: null
any help would be greatly appreciated and thanks in advance
EDIT: here is my code for my games class
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;
}
}
© Stack Overflow or respective owner