0
votes

This my code for webservice.

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package customer;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.jws.WebService;

/**
 *
 * @author Mihir
 */
public class Customer {
  String date1;
  Format formatter;
  Date date = new Date();
    public String feedback(String contactno,String comments,String ambience,String service,String 

food,String email,String custno,String custname,String storeno,String sno) 
    {

  formatter = new SimpleDateFormat("dd/MM/yy");
  date1 = formatter.format(date);
  Connection con = null;
  PreparedStatement prest;
  try{
  Class.forName("com.mysql.jdbc.Driver");
  con = DriverManager.getConnection("jdbc:mysql://localhost:3306/feedback","root","root");
  Statement stmt = con.createStatement();



      String sql = "INSERT INTO fb(contact_no, 

date,comments,ambience,service,food,email,cust_no,cust_name,store_no,s_no) " +
                    "VALUES ('"+contactno+"', 

'"+date1+"','"+comments+"','"+ambience+"','"+service+"','"+food+"','"+email+"','"+custno+"',

'"+custname+"','"+storeno+"','"+sno+"')";

stmt.execute(sql);


  }

  catch (Exception e){
  e.printStackTrace();
  }
        return null;
  }

}

Now this is what I am trying to do.

  1. Creating folder in webapps in Tomcat with name customer_customer.
  2. Inside that two more folder - WEB-INF META-INF
  3. Inside META_INF context.xml with content-

  4. Inside WEB-INF

4.a. classes/customer/Customer.class

4b. lib folder with jar - I. webservices-api.jar II. webservices-extra.jar III.webservices--extra-api.jar IV. webservices-rt.jar V. webservices-tools.jar VI. mysql-connector-java-5.1.18-bin.jar

4c. web.xml -

    <?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <listener>
        <listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class>
    </listener>
    <servlet>
        <servlet-name>Customer</servlet-name>
        <servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Customer</servlet-name>
        <url-pattern>/feedback</url-pattern>
    </servlet-mapping>

</web-app>  

4d. sun-jaxws.xml

<?xml version="1.0" encoding="UTF-8"?>
<endpoints version="2.0" xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime">
  <endpoint implementation="ws.Customer" name="Adder" url-pattern="/feedback"/>
</endpoints>
1
content.xml '<?xml version="1.0" encoding="UTF-8"?> <Context antiJARLocking="true" path="/customer_customer"/>'J_Haskin
And what exactly happens when you try to deploy that code?home
If I add Any simple code like adding two numbers then it will get deployed and works fine but when I am trying to add MySQL implementation, Tomcat shows this message FAIL - Application at context path /customer_customer could not be started. I separately run my class file and its working fine.It happens with every webservice with mysql. Note - Its working fine with glassfish as well.J_Haskin
You should find a stacktrace somewhere in the Tomcat logs. Please update your question with that...home
Unable to open Event Mutex. I dont use Tomcat so dont know how to get around that.J_Haskin

1 Answers

1
votes

I got it now and its working I make changes so that my package an name are different from each other and specified @Webservice before my class name.I already tested the Webservice and implemented on my android phone. Thank you all for your comments.