Use data that is in the database

-1

I'm creating a Quiz. I was able to create the screen to create the questions, it is recording in the database all right. But now I'm going to do the "game" itself, so I would have to get a question that is stored in the bank and return to the screen, how do I do this query in the bank? ResultSet is giving the error code below.

 String SQL = "Aqui montaria o SQL de Busca de Dificuldades no jogo
 WHERE" ;

 String Nivel=" ";

 if(JrbFácil.isSelected()){ 

 SQL += "DICICULDADE = FACIL"

 }

 if(JrbMédio.isSelected()){

 SQL += "DICICULDADE = MEDIO"

 }

 if(JrbDificil.isSelected()){

 SQL += "DICICULDADE = DIFICIL"

 }

 PreparedStatement stmt = this.connection.prepareStatement("select *from quiz where id = ?");

 stmt.setInt(1, 1); 

 ResultSet rs = stmt.executeQuery();
    
asked by anonymous 04.09.2014 / 22:41

2 answers

1

1-) Test the query in the database to see if it is returning data. 2-) Check that both SELECTS are correct, through the above step. 3-) Verify that the application is running SELECT. 4-) Do not forget to put a space after the WHERE when mounting the query in this way. 5-) Make sure the connection is ok.

Using the result set:

PreparedStatement stmt = this.connection.prepareStatement("select * from quiz where id = ?");

stmt.setInt(1, 1); 

ResultSet rs = stmt.executeQuery();
String campo1;
String campo2;
while(rs.next()){
 campo1 = rs.getString("NOME DO CAMPO 1");
 campo2 = rs.getString("NOME DO CAMPO 2");
}

Remember, it is considered good practice to use the field name instead of the index.

It was just assumptions, post the stacktrace or compile error to help solve the problem

    
06.09.2014 / 14:45
0

Although the question is unclear, have you tried to check if your SQL is correct?

select *from quiz where id = ?

I think the correct one would be:

select * from quiz where id = ?
    
05.09.2014 / 03:29