Actually i implemented this links(
http://theopentutorials.com/examples/java-ee/jax-ws/create-and-consume-web-service-using-jax-ws/) example and after that according to my requirement i added the code for connection to database as follows . But it gave run time error which also i am mentioning .
@WebService
public class calculator
{
public int add(int a, int b)
{
return (a + b);
}
public int sub(int a, int b) throws ClassNotFoundException, SQLException
{
Connection conn1=new connection().getConnection();
Statement stmt = null;
ResultSet rs = null;
int rowCount = -1;
rs = stmt.executeQuery("SELECT COUNT(*) FROM hospital_status");
// get the number of rows from the result set
rs.next();
rowCount = rs.getInt(1);
return rowCount;
}
class connection
{
public Connection getConnection() throws ClassNotFoundException, SQLException
{
Statement stmt = null;
ResultSet rs = null;
Connection conn;
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://192.168.2.8/hospital_data";
String username = "root";
String password = "mysql";
int rowCount = -1;
Class.forName(driver);
conn = DriverManager.getConnection(url, username, password);
return conn;
}
}
**************************************************************
My web Service and my database are on the same PC
Run time errors(though this webService gets published but what i get as row count is -1 as declared by the variable i.e connection to the database on my pc is not made .)
[Error] A class/interface with the same name "com.open.calc.SQLException" is already in use.Use a class customization to resolve this conflict.
line 45 of
http://localhost:8080/calcws/calculator?xsd=1
[ERROR] this error is caused beacuse on windows you cannot have both "SQLException.java" and "SQLException.java" in the same directory.