• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem in connecting mysql database to JAX-WS

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually i want to create a jax-ws whose client will access it from android . So please guide me how to connect database to webservice

Diagramatical representation of my project

client(android) ------------------WebSevice----------------------MySql(database)

So the problem is coming in the later part of connecting webservice with the database .

when i run it , i get run time errors.

 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And what error did you get? A stack trace will help.

How are you connecting to the database in the code?
 
Salil Vishnu Kapur
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
K. Tsang
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Salil Vishnu Kapur wrote:
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 .)



Try localhost in the connection url. Also the getConnection() method can be static. Hence you don't need to "new <classname>".


Salil Vishnu Kapur wrote:
[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.



Why aren't you using the java API's java.sql.SQLException?
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic