When I run the class Test01, the following error appears: "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '=' CLIENT '' at line 1
CounterModel
package model;
import accesobd.AccesoBD;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
public class ContadorModel {
public static String getContador(String nombreTabla) throws Exception {
Connection cn=AccesoBD.getConnection();
PreparedStatement ps= null;
ResultSet rs= null;
String contador= null;
String sql= "Select right(concat(repeat('0', int_contlongitud)," +
"int_contitem),int_contlongitud) as item from contador" +
"where vch_conttabla = ?";
ps=cn.prepareStatement(sql);
nombreTabla = nombreTabla.toUpperCase();
ps.setString(1, nombreTabla);
rs=ps.executeQuery();
if(!rs.next()){
return contador;
}
contador = rs.getString("item");
sql="update contador" +
"set int_contitem= int_contitem +1"+
"where vch_conttabla= ?";
ps=cn.prepareStatement(sql);
ps.setString(1, nombreTabla);
ps.executeUpdate();
rs.close();
ps.close();
return contador;
}//getContador
}//Contador model
Test01
I used CounterModel.getContent ("client") where I put customer to have as item 00021.
I show the query that is correct in Workbench Select right (concat (repeat ('0', int_contlongitude), int_contitem), int_contlongitud) as item from counter where vch_conttabla = 'client'
package Pruebas;
import model.ContadorModel;
import java.util.logging.Level;
import java.util.logging.Logger;
public class Prueba01 {
public static void main(String[] args) {
try {
System.out.println(ContadorModel.getContador("cliente"));
} catch (Exception ex) {
Logger.getLogger(Prueba01.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
Please someone to help me see what my mistake is, because it tells me that the client is wrong and I do not understand much.