credo che il problema sia qui. c'è un array e credo che devo applicare un ciclo for.
codice:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Visualizzare {
public static Object[] visualizza(String nomeInserito) throws ClassNotFoundException, SQLException {
String driver = "com.mysql.jdbc.Driver";
Class.forName(driver);
String url = "jdbc:mysql://localhost:3306/Rubrica";
Connection con = DriverManager.getConnection(url,"*****","******");
Statement cmd = con.createStatement();
String qry = "SELECT nome, cognome, indirizzo, telefono FROM new_table WHERE cognome=" + "'" + nomeInserito + "'" ;
ResultSet res = cmd.executeQuery(qry);
Object[] array = new Object[4];
if (!(res.equals(""))) {
while (res.next()) {
array[0] = res.getString("nome");
array[1] = res.getString("cognome");
array[2] = res.getString("indirizzo");
array[3] = res.getString("telefono");
}
}else if (!(res.first())) {
array[0] = "utente non trovato";
array[1] = "";
array[2] = "";
array[3] = "";
//System.out.println("nome non presente nella rubrica");
}
returnarray;
}
}