I can't make an Insert in MYSQL with a SOAP web service in Java using JDBC driver












1















Hi im trying to test a web service Soap java which is connected to mysql localhost (xampp) but i can't insert any row in the data base
Here is my code



Conexion.java



import java.sql.Connection
import java.sql.DriverManager

public class Conexion {

public static final Connection ConectarMySQL() throws SQLException
{
Connection conn;
try
{
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/controldecalidad", "root", "");
}
catch(SQLException ex)
{
throw new SQLException(ex.getMessage());
}
return conn;
}


}



and here is the webservice



 @WebMethod(operationName= "registra_rechazo")   
public void registra_rechazo(@WebParam(name = "SKU")String SKU,@WebParam(name = "fecha")String fecha,
@WebParam(name = "num_captura")String num_captura,@WebParam(name = "pesoCaptura") int pesoCaptura)
{
try
{
Connection conn = Conexion.ConectarMySQL();
String sql = "INSERT INTO registra_rechazo VALUES(?,?,?,?)";
PreparedStatement pst = conn.prepareStatement(sql);
pst.setString(1, SKU);
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-mm-dd");
pst.setString(2, dateFormat.format(fecha));
pst.setString(3, num_captura);
pst.setInt(4, pesoCaptura);
pst.execute();
pst.close();
conn.close();

}
catch(SQLException Ex)
{

}
}


and here is the error
https://i.stack.imgur.com/aWO16.png



UPDATE!! i checked my proyect and i got this new error
https://i.stack.imgur.com/uHRQW.png



what im missing? please help!!!!










share|improve this question

























  • java.lang.reflect.InvocationTargetException is thrown when the method you invoked tries to invoke another method that throws an exception, so my advice would be to check the log and try to follow the stack trace to see where the error originally came from

    – mur762
    Nov 21 '18 at 0:23













  • Hi! thank you for you feedback y re-checked the conexion class and i try it in other proyect and was correct with no errors so de Connection instance is not the problem, then i change prepared statement to stament and i had a java.lang.NullPointerException error :/

    – Cristian Araya
    Nov 21 '18 at 17:05











  • in the update, is that the complete error message? If it's not post the whole error, I believe it should list what causes it exactly

    – mur762
    Nov 21 '18 at 17:50
















1















Hi im trying to test a web service Soap java which is connected to mysql localhost (xampp) but i can't insert any row in the data base
Here is my code



Conexion.java



import java.sql.Connection
import java.sql.DriverManager

public class Conexion {

public static final Connection ConectarMySQL() throws SQLException
{
Connection conn;
try
{
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/controldecalidad", "root", "");
}
catch(SQLException ex)
{
throw new SQLException(ex.getMessage());
}
return conn;
}


}



and here is the webservice



 @WebMethod(operationName= "registra_rechazo")   
public void registra_rechazo(@WebParam(name = "SKU")String SKU,@WebParam(name = "fecha")String fecha,
@WebParam(name = "num_captura")String num_captura,@WebParam(name = "pesoCaptura") int pesoCaptura)
{
try
{
Connection conn = Conexion.ConectarMySQL();
String sql = "INSERT INTO registra_rechazo VALUES(?,?,?,?)";
PreparedStatement pst = conn.prepareStatement(sql);
pst.setString(1, SKU);
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-mm-dd");
pst.setString(2, dateFormat.format(fecha));
pst.setString(3, num_captura);
pst.setInt(4, pesoCaptura);
pst.execute();
pst.close();
conn.close();

}
catch(SQLException Ex)
{

}
}


and here is the error
https://i.stack.imgur.com/aWO16.png



UPDATE!! i checked my proyect and i got this new error
https://i.stack.imgur.com/uHRQW.png



what im missing? please help!!!!










share|improve this question

























  • java.lang.reflect.InvocationTargetException is thrown when the method you invoked tries to invoke another method that throws an exception, so my advice would be to check the log and try to follow the stack trace to see where the error originally came from

    – mur762
    Nov 21 '18 at 0:23













  • Hi! thank you for you feedback y re-checked the conexion class and i try it in other proyect and was correct with no errors so de Connection instance is not the problem, then i change prepared statement to stament and i had a java.lang.NullPointerException error :/

    – Cristian Araya
    Nov 21 '18 at 17:05











  • in the update, is that the complete error message? If it's not post the whole error, I believe it should list what causes it exactly

    – mur762
    Nov 21 '18 at 17:50














1












1








1








Hi im trying to test a web service Soap java which is connected to mysql localhost (xampp) but i can't insert any row in the data base
Here is my code



Conexion.java



import java.sql.Connection
import java.sql.DriverManager

public class Conexion {

public static final Connection ConectarMySQL() throws SQLException
{
Connection conn;
try
{
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/controldecalidad", "root", "");
}
catch(SQLException ex)
{
throw new SQLException(ex.getMessage());
}
return conn;
}


}



and here is the webservice



 @WebMethod(operationName= "registra_rechazo")   
public void registra_rechazo(@WebParam(name = "SKU")String SKU,@WebParam(name = "fecha")String fecha,
@WebParam(name = "num_captura")String num_captura,@WebParam(name = "pesoCaptura") int pesoCaptura)
{
try
{
Connection conn = Conexion.ConectarMySQL();
String sql = "INSERT INTO registra_rechazo VALUES(?,?,?,?)";
PreparedStatement pst = conn.prepareStatement(sql);
pst.setString(1, SKU);
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-mm-dd");
pst.setString(2, dateFormat.format(fecha));
pst.setString(3, num_captura);
pst.setInt(4, pesoCaptura);
pst.execute();
pst.close();
conn.close();

}
catch(SQLException Ex)
{

}
}


and here is the error
https://i.stack.imgur.com/aWO16.png



UPDATE!! i checked my proyect and i got this new error
https://i.stack.imgur.com/uHRQW.png



what im missing? please help!!!!










share|improve this question
















Hi im trying to test a web service Soap java which is connected to mysql localhost (xampp) but i can't insert any row in the data base
Here is my code



Conexion.java



import java.sql.Connection
import java.sql.DriverManager

public class Conexion {

public static final Connection ConectarMySQL() throws SQLException
{
Connection conn;
try
{
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/controldecalidad", "root", "");
}
catch(SQLException ex)
{
throw new SQLException(ex.getMessage());
}
return conn;
}


}



and here is the webservice



 @WebMethod(operationName= "registra_rechazo")   
public void registra_rechazo(@WebParam(name = "SKU")String SKU,@WebParam(name = "fecha")String fecha,
@WebParam(name = "num_captura")String num_captura,@WebParam(name = "pesoCaptura") int pesoCaptura)
{
try
{
Connection conn = Conexion.ConectarMySQL();
String sql = "INSERT INTO registra_rechazo VALUES(?,?,?,?)";
PreparedStatement pst = conn.prepareStatement(sql);
pst.setString(1, SKU);
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-mm-dd");
pst.setString(2, dateFormat.format(fecha));
pst.setString(3, num_captura);
pst.setInt(4, pesoCaptura);
pst.execute();
pst.close();
conn.close();

}
catch(SQLException Ex)
{

}
}


and here is the error
https://i.stack.imgur.com/aWO16.png



UPDATE!! i checked my proyect and i got this new error
https://i.stack.imgur.com/uHRQW.png



what im missing? please help!!!!







java mysql web-services soap netbeans-8






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 17:10







Cristian Araya

















asked Nov 20 '18 at 21:22









Cristian ArayaCristian Araya

63




63













  • java.lang.reflect.InvocationTargetException is thrown when the method you invoked tries to invoke another method that throws an exception, so my advice would be to check the log and try to follow the stack trace to see where the error originally came from

    – mur762
    Nov 21 '18 at 0:23













  • Hi! thank you for you feedback y re-checked the conexion class and i try it in other proyect and was correct with no errors so de Connection instance is not the problem, then i change prepared statement to stament and i had a java.lang.NullPointerException error :/

    – Cristian Araya
    Nov 21 '18 at 17:05











  • in the update, is that the complete error message? If it's not post the whole error, I believe it should list what causes it exactly

    – mur762
    Nov 21 '18 at 17:50



















  • java.lang.reflect.InvocationTargetException is thrown when the method you invoked tries to invoke another method that throws an exception, so my advice would be to check the log and try to follow the stack trace to see where the error originally came from

    – mur762
    Nov 21 '18 at 0:23













  • Hi! thank you for you feedback y re-checked the conexion class and i try it in other proyect and was correct with no errors so de Connection instance is not the problem, then i change prepared statement to stament and i had a java.lang.NullPointerException error :/

    – Cristian Araya
    Nov 21 '18 at 17:05











  • in the update, is that the complete error message? If it's not post the whole error, I believe it should list what causes it exactly

    – mur762
    Nov 21 '18 at 17:50

















java.lang.reflect.InvocationTargetException is thrown when the method you invoked tries to invoke another method that throws an exception, so my advice would be to check the log and try to follow the stack trace to see where the error originally came from

– mur762
Nov 21 '18 at 0:23







java.lang.reflect.InvocationTargetException is thrown when the method you invoked tries to invoke another method that throws an exception, so my advice would be to check the log and try to follow the stack trace to see where the error originally came from

– mur762
Nov 21 '18 at 0:23















Hi! thank you for you feedback y re-checked the conexion class and i try it in other proyect and was correct with no errors so de Connection instance is not the problem, then i change prepared statement to stament and i had a java.lang.NullPointerException error :/

– Cristian Araya
Nov 21 '18 at 17:05





Hi! thank you for you feedback y re-checked the conexion class and i try it in other proyect and was correct with no errors so de Connection instance is not the problem, then i change prepared statement to stament and i had a java.lang.NullPointerException error :/

– Cristian Araya
Nov 21 '18 at 17:05













in the update, is that the complete error message? If it's not post the whole error, I believe it should list what causes it exactly

– mur762
Nov 21 '18 at 17:50





in the update, is that the complete error message? If it's not post the whole error, I believe it should list what causes it exactly

– mur762
Nov 21 '18 at 17:50












1 Answer
1






active

oldest

votes


















0














I FINALLY SOLVED IT !!



in the class Conexion y remove the static final and i create a constructor for this class



public class Conexion {

public Conexion(){

}
public Connection getConecction()
{
Connection con = null;
try{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/controldecalidad", "root", "");
}catch(SQLException ex){
}
catch(Exception ex){
}
return con;
}
}


then i created a class who have all the operations



public class Operaciones 
{
Conexion conexion;

public Operaciones()
{
conexion = new Conexion();
}


public boolean registra_rechazo(String SKU,String fecha,String num_captura,int pesoCaptura)
{
Boolean bandera=false;
try
{
Connection conn = conexion.getConecction();
java.util.Date utilStartDate = new java.util.Date(fecha);
java.sql.Date sqlStartDate = new java.sql.Date(utilStartDate.getTime());
String sql = "INSERT INTO registra_rechazo VALUES(?,?,?,?)";
PreparedStatement pst = conn.prepareStatement(sql);
pst.setString(1, SKU);
pst.setDate(2, sqlStartDate);
pst.setString(3, num_captura);
pst.setInt(4, pesoCaptura);
if(pst.executeUpdate()!=-1){
bandera = true;
return bandera;
}
else{
bandera = false;
return bandera;

}

}
catch(SQLException Ex)
{

}
return bandera;
}
}


then i call the method in the web service, but first the web method must be created by add operation in the web service like the image



https://i.stack.imgur.com/HjAHk.png



i dont know why but the method only works if you created the method with that wizard



@WebMethod(operationName = "operation")
public boolean operation(@WebParam(name = "SKU") String SKU, @WebParam(name = "fecha") String fecha, @WebParam(name = "num_captura") String num_captura, @WebParam(name = "peso_captura") int peso_captura) {
//TODO write your implementation code here:
Operaciones op = new Operaciones();
return op.registra_rechazo(SKU,fecha,num_captura,peso_captura);
}


and then the web method must return something, with void will not work






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53401732%2fi-cant-make-an-insert-in-mysql-with-a-soap-web-service-in-java-using-jdbc-drive%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    I FINALLY SOLVED IT !!



    in the class Conexion y remove the static final and i create a constructor for this class



    public class Conexion {

    public Conexion(){

    }
    public Connection getConecction()
    {
    Connection con = null;
    try{
    Class.forName("com.mysql.jdbc.Driver");
    con = DriverManager.getConnection("jdbc:mysql://localhost:3306/controldecalidad", "root", "");
    }catch(SQLException ex){
    }
    catch(Exception ex){
    }
    return con;
    }
    }


    then i created a class who have all the operations



    public class Operaciones 
    {
    Conexion conexion;

    public Operaciones()
    {
    conexion = new Conexion();
    }


    public boolean registra_rechazo(String SKU,String fecha,String num_captura,int pesoCaptura)
    {
    Boolean bandera=false;
    try
    {
    Connection conn = conexion.getConecction();
    java.util.Date utilStartDate = new java.util.Date(fecha);
    java.sql.Date sqlStartDate = new java.sql.Date(utilStartDate.getTime());
    String sql = "INSERT INTO registra_rechazo VALUES(?,?,?,?)";
    PreparedStatement pst = conn.prepareStatement(sql);
    pst.setString(1, SKU);
    pst.setDate(2, sqlStartDate);
    pst.setString(3, num_captura);
    pst.setInt(4, pesoCaptura);
    if(pst.executeUpdate()!=-1){
    bandera = true;
    return bandera;
    }
    else{
    bandera = false;
    return bandera;

    }

    }
    catch(SQLException Ex)
    {

    }
    return bandera;
    }
    }


    then i call the method in the web service, but first the web method must be created by add operation in the web service like the image



    https://i.stack.imgur.com/HjAHk.png



    i dont know why but the method only works if you created the method with that wizard



    @WebMethod(operationName = "operation")
    public boolean operation(@WebParam(name = "SKU") String SKU, @WebParam(name = "fecha") String fecha, @WebParam(name = "num_captura") String num_captura, @WebParam(name = "peso_captura") int peso_captura) {
    //TODO write your implementation code here:
    Operaciones op = new Operaciones();
    return op.registra_rechazo(SKU,fecha,num_captura,peso_captura);
    }


    and then the web method must return something, with void will not work






    share|improve this answer




























      0














      I FINALLY SOLVED IT !!



      in the class Conexion y remove the static final and i create a constructor for this class



      public class Conexion {

      public Conexion(){

      }
      public Connection getConecction()
      {
      Connection con = null;
      try{
      Class.forName("com.mysql.jdbc.Driver");
      con = DriverManager.getConnection("jdbc:mysql://localhost:3306/controldecalidad", "root", "");
      }catch(SQLException ex){
      }
      catch(Exception ex){
      }
      return con;
      }
      }


      then i created a class who have all the operations



      public class Operaciones 
      {
      Conexion conexion;

      public Operaciones()
      {
      conexion = new Conexion();
      }


      public boolean registra_rechazo(String SKU,String fecha,String num_captura,int pesoCaptura)
      {
      Boolean bandera=false;
      try
      {
      Connection conn = conexion.getConecction();
      java.util.Date utilStartDate = new java.util.Date(fecha);
      java.sql.Date sqlStartDate = new java.sql.Date(utilStartDate.getTime());
      String sql = "INSERT INTO registra_rechazo VALUES(?,?,?,?)";
      PreparedStatement pst = conn.prepareStatement(sql);
      pst.setString(1, SKU);
      pst.setDate(2, sqlStartDate);
      pst.setString(3, num_captura);
      pst.setInt(4, pesoCaptura);
      if(pst.executeUpdate()!=-1){
      bandera = true;
      return bandera;
      }
      else{
      bandera = false;
      return bandera;

      }

      }
      catch(SQLException Ex)
      {

      }
      return bandera;
      }
      }


      then i call the method in the web service, but first the web method must be created by add operation in the web service like the image



      https://i.stack.imgur.com/HjAHk.png



      i dont know why but the method only works if you created the method with that wizard



      @WebMethod(operationName = "operation")
      public boolean operation(@WebParam(name = "SKU") String SKU, @WebParam(name = "fecha") String fecha, @WebParam(name = "num_captura") String num_captura, @WebParam(name = "peso_captura") int peso_captura) {
      //TODO write your implementation code here:
      Operaciones op = new Operaciones();
      return op.registra_rechazo(SKU,fecha,num_captura,peso_captura);
      }


      and then the web method must return something, with void will not work






      share|improve this answer


























        0












        0








        0







        I FINALLY SOLVED IT !!



        in the class Conexion y remove the static final and i create a constructor for this class



        public class Conexion {

        public Conexion(){

        }
        public Connection getConecction()
        {
        Connection con = null;
        try{
        Class.forName("com.mysql.jdbc.Driver");
        con = DriverManager.getConnection("jdbc:mysql://localhost:3306/controldecalidad", "root", "");
        }catch(SQLException ex){
        }
        catch(Exception ex){
        }
        return con;
        }
        }


        then i created a class who have all the operations



        public class Operaciones 
        {
        Conexion conexion;

        public Operaciones()
        {
        conexion = new Conexion();
        }


        public boolean registra_rechazo(String SKU,String fecha,String num_captura,int pesoCaptura)
        {
        Boolean bandera=false;
        try
        {
        Connection conn = conexion.getConecction();
        java.util.Date utilStartDate = new java.util.Date(fecha);
        java.sql.Date sqlStartDate = new java.sql.Date(utilStartDate.getTime());
        String sql = "INSERT INTO registra_rechazo VALUES(?,?,?,?)";
        PreparedStatement pst = conn.prepareStatement(sql);
        pst.setString(1, SKU);
        pst.setDate(2, sqlStartDate);
        pst.setString(3, num_captura);
        pst.setInt(4, pesoCaptura);
        if(pst.executeUpdate()!=-1){
        bandera = true;
        return bandera;
        }
        else{
        bandera = false;
        return bandera;

        }

        }
        catch(SQLException Ex)
        {

        }
        return bandera;
        }
        }


        then i call the method in the web service, but first the web method must be created by add operation in the web service like the image



        https://i.stack.imgur.com/HjAHk.png



        i dont know why but the method only works if you created the method with that wizard



        @WebMethod(operationName = "operation")
        public boolean operation(@WebParam(name = "SKU") String SKU, @WebParam(name = "fecha") String fecha, @WebParam(name = "num_captura") String num_captura, @WebParam(name = "peso_captura") int peso_captura) {
        //TODO write your implementation code here:
        Operaciones op = new Operaciones();
        return op.registra_rechazo(SKU,fecha,num_captura,peso_captura);
        }


        and then the web method must return something, with void will not work






        share|improve this answer













        I FINALLY SOLVED IT !!



        in the class Conexion y remove the static final and i create a constructor for this class



        public class Conexion {

        public Conexion(){

        }
        public Connection getConecction()
        {
        Connection con = null;
        try{
        Class.forName("com.mysql.jdbc.Driver");
        con = DriverManager.getConnection("jdbc:mysql://localhost:3306/controldecalidad", "root", "");
        }catch(SQLException ex){
        }
        catch(Exception ex){
        }
        return con;
        }
        }


        then i created a class who have all the operations



        public class Operaciones 
        {
        Conexion conexion;

        public Operaciones()
        {
        conexion = new Conexion();
        }


        public boolean registra_rechazo(String SKU,String fecha,String num_captura,int pesoCaptura)
        {
        Boolean bandera=false;
        try
        {
        Connection conn = conexion.getConecction();
        java.util.Date utilStartDate = new java.util.Date(fecha);
        java.sql.Date sqlStartDate = new java.sql.Date(utilStartDate.getTime());
        String sql = "INSERT INTO registra_rechazo VALUES(?,?,?,?)";
        PreparedStatement pst = conn.prepareStatement(sql);
        pst.setString(1, SKU);
        pst.setDate(2, sqlStartDate);
        pst.setString(3, num_captura);
        pst.setInt(4, pesoCaptura);
        if(pst.executeUpdate()!=-1){
        bandera = true;
        return bandera;
        }
        else{
        bandera = false;
        return bandera;

        }

        }
        catch(SQLException Ex)
        {

        }
        return bandera;
        }
        }


        then i call the method in the web service, but first the web method must be created by add operation in the web service like the image



        https://i.stack.imgur.com/HjAHk.png



        i dont know why but the method only works if you created the method with that wizard



        @WebMethod(operationName = "operation")
        public boolean operation(@WebParam(name = "SKU") String SKU, @WebParam(name = "fecha") String fecha, @WebParam(name = "num_captura") String num_captura, @WebParam(name = "peso_captura") int peso_captura) {
        //TODO write your implementation code here:
        Operaciones op = new Operaciones();
        return op.registra_rechazo(SKU,fecha,num_captura,peso_captura);
        }


        and then the web method must return something, with void will not work







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 22 '18 at 1:04









        Cristian ArayaCristian Araya

        63




        63
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53401732%2fi-cant-make-an-insert-in-mysql-with-a-soap-web-service-in-java-using-jdbc-drive%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            How to change which sound is reproduced for terminal bell?

            Can I use Tabulator js library in my java Spring + Thymeleaf project?

            Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents