noi Stiamo usando questo file per la connessione e l'esecuzione delle query:
codice:
import java.sql.*;
public class SQLManager {
public static Connection conn;
private PreparedStatement pstmt;
private static ResultSet rs;
@SuppressWarnings("unused")
private static Statement Stm;
//private static String query;
//Apre la connessione al database
public SQLManager(String driver, String connectionURL, String userDB, String passwordDB){
try{
Class.forName(driver);
conn = DriverManager.getConnection(connectionURL , userDB, passwordDB);
Stm = conn.createStatement();
}catch(Exception ex){
System.out.println("SQLException: " + ex.getMessage());
}
}
//Chiude la connessione al database
public void close(){
try {
if(rs!=null)
rs.close();
if(pstmt!=null)
pstmt.close();
if(conn!=null)
conn.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
}
public ResultSet execute(String anSQLString) {
try{
rs = Stm.executeQuery(anSQLString);
}catch(Exception ex){
ex.printStackTrace();
}
return rs;
}
}// fine eseguiQuery
codice:
String[]item;
SQLManager sqlm = new SQLManager("com.mysql.jdbc.Driver","jdbc:mysql://localhost:3306/schedule","root","root");
String query = "select cognome from Utente";
sqlm.execute(query);
int i=0;
while(rs.next()){
item[i]= rs.getString(cognome);
i++;
}
JComboBox jComboDocenti = new JComboBox(item);
PannelloBottoni.add(jComboDocenti);
jComboDocenti.setBounds(1104, 120, 145, 22);
}
Come devo fare?? non i riconosce il ResultSet... nel file contenente la ComboBox...