Good day. I have coded a server application that handles many socket connections from app clients, each client request to the server certain information from a sql database to display in its gui interface, calling a method inside the server to make the query and retrieve the data.
In some cases, the application hangs while tries to retrieve the data from the server, i want to my application does not freeze, but instead show a progress bar or an loading animation while retrieving the request. Is this somehow possible? I've read about threads, workers and sql pools, but i dont know exactly what it fits on my needs.
I have this class on server app to manage my queries:
final class QueryManager {
//abstract System.out.println("Ya");
static Connection con = null;
static String LoginMsg = "No conectado";
public static void init(){
try{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con=DriverManager.getConnection("jdbc:sqlserver://PERSONAL:49617;databaseName=prueba","sa", "12345678");
System.out.println("Conexión Establecida");
LoginMsg = "Conectado al Servidor";
}catch(ClassNotFoundException | SQLException e){
e.printStackTrace();
System.out.println("Exception: " + e.getMessage());
}
}
public static void Query(String query, int i){
try{
Statement st = con.createStatement();
try (ResultSet rset = st.executeQuery(Pquery(query))) {
rset.next();
System.out.println(rset.getString(1)+i);
}
}catch(SQLException e){
System.out.println(e);
}
}
public static String Pquery(String pquery){
return pquery;
}
public static boolean Login(String user, String pass){
boolean r = false;
try{
Statement getCon = con.createStatement();
ResultSet EQuery = getCon.executeQuery("select * from users where usuario ='"+user+"' and contrasena ='"+pass+"'");
EQuery.next();
if(EQuery.getString(1) != null){
r = true;
LoginMsg = "Bienvenido";
}else{
r = false;
}
EQuery.close();
}catch(SQLException e){
System.out.println(e);
}
return r;
}
public static String getLoginMsg(){
return LoginMsg;
}
public static void printer(){
System.out.println("Ya");
}
}
Thank you in advance, any help on logic also will be much appreciated.
EDIT:
I have found this example and might be usefull. Thank you for your support.