Good morning, have all of you. My question is this, I have a coupon printing system for raffles, made in NetBeans (Servlets), this system has the option to log in and enter, until there everything works fine. The problem begins when registering the coupons per customer for example I register 5000 credits and print 5 coupons, but when another user logs in and registers the credits of another customer, I believe that it enters into internal conflict and throws a null value, I saw on the internet that the Apache Tomcat server internally manages the users connected to the system, I also saw that for that type of multi-user system you have to work with Threads, so my doubt would be that. What do you recommend me to do?
This is the error that prints me.
This is my code to log in.
public int idUsuario(entusuario enti) {
int id=0;
try {
ps=xcone.prepareStatement("select idPersona from operador where nombreusuario=(?) and claveusuario=(?)");
//ps=cone.xconMysql().prepareStatement("select idPersona from operador where nombreusuario=(?) and claveusuario=(?)");
ps.setString(1, enti.getNombreusuario());
ps.setString(2, enti.getClaveusuario());
rs=ps.executeQuery();
while(rs.next())
{
id=rs.getInt(1);
}
//System.err.println("el id del cliente es "+id);
}catch(SQLException e){
System.err.println("Error al otbener el id del cliente "+e.getMessage());
}
return id;
}
public ArrayList<entusuario> getPersona(int id){
ArrayList<entusuario> datos=new ArrayList<>();
try {
ps=xcone.prepareStatement("select per.idpersona,\n" +
//ps=cone.xconMysql().prepareStatement("select per.idpersona,\n" +
"per.nombres,\n" +
"per.apellidos,\n" +
"op.idoperador,\n" +
"op.nombreusuario,\n" +
"soc.idSocio,\n" +
"soc.nombreSocio \n" +
"from persona per\n" +
"inner join operador op on per.idPersona=op.idpersona \n" +
"inner join socio soc on soc.idSocio=op.idSocio \n"+
"where per.idPersona=(?)");
ps.setInt(1, id);
rs=ps.executeQuery();
while(rs.next())
{
ent=new entusuario();
ent.setIdpersona(rs.getInt(1));
ent.setNombres(rs.getString(2));
ent.setApellidos(rs.getString(3));
ent.setIdoperador(rs.getInt(4));
ent.setNombreusuario(rs.getString(5));
ent.setIdSocio(rs.getInt(6));
ent.setNombreSocio(rs.getString(7));
datos.add(ent);
System.err.println("Usuario "+ent.getNombres()+" logueado");
}
} catch (SQLException e) {
System.err.println("Error al obtener datos del usuario "+e.getMessage());
return null;
}
return datos;
}
What I could understand is that he is connecting many times to the BD.