Link to home
Start Free TrialLog in
Avatar of Mat Smith
Mat Smith

asked on

Soap web services on Tomcat to insert data to a database

Hello,

I generated soap web services using Eclipse JEE, which then I deployed ( .war) on Tomcat 7.0 on Centos 7 -  this works fine.
The aim is to insert a data received in an xml and insert it to an Oracle table.

I've added the below code to a java class file, which meant to do some insert statement ( which is valid ) , with hardcoded values, just to prove I can do it.

    public void InsertValue(String MessageId, String value){
    	try{

    	Connection con=null;
    	Class.forName("oracle.jdbc.driver.OracleDriver");


    	con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xxx", "xxx","xxx");
    	Statement s = con.createStatement();

    	s.execute("INSERT INTO ping_message (message_id,dstamp) VALUES ('1',To_char(SYSDATE))");
    	con.setAutoCommit(true);
    	s.close();
    	con.close();
    	}catch(Exception e){
    	System.out.println("ERROR: "+e.getMessage());
    	}
    	}
    

Open in new window


Unfortunately, this does not work. I wonder if this is because of the java code or Tomcat needs some db drivers in order to establish a connection the database ?

btw, my java skills are being developed as I type this :)
Avatar of girionis
girionis
Flag of Greece image

What do you mean by "does not work"? Do you get any error messages?
Avatar of Mat Smith
Mat Smith

ASKER

No, I don't get any errors. It just doesn't do the insert when calling a web service.
Basically my question at the moment is if my Java code looks OK  and if I need anything special on Tomcat to be able to receive a soap request and then insert the xml data to an oracle database....or it simply should work.
You do not need to do anything else. Are you sure your method is called?
Hi Girionis,

You made a very good point here. I put my java sql code to a wrong java class. Now it's in the right one, however, I'm getting now a java error
"void is an invalid type for the variable InsertValue"  and it pointed me to Interface DataSource

https://docs.oracle.com/javase/8/docs/api/javax/sql/DataSource.html

I understand that I have to rewrite "my" code ?
Are you writing Android code? Which line has the error?
no, I'm not android. It's a dynamic web app ( web services ).
The line with the error is  public void InsertValue

package com.aaaa.WebServices;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

public class bbbbImpl
 implements com.aaaa.WebServices.cccc{
    public com.aaaa.WebServices.SendPing_WMSResponse sendPing_WMS(com.aaa.WebServices.SendPing_WMS parameters) throws java.rmi.RemoteException {
     
        public void InsertValue(String MessageId, String value){
        	try{
        	Connection con=null;
        	Class.forName("oracle.jdbc.driver.OracleDriver");
        	con=DriverManager.getConnection("jdbc:oracle:thin:@172.16.76.100:1521:dcs", "dcsdba","dcsabd");
        	Statement s = con.createStatement();
        	//Configure the SQL query as you want, the table must exists 
        	s.execute("INSERT INTO dcsdba.ping_message (message_id,dstamp) VALUES ('1',To_char(SYSDATE))");
        	con.setAutoCommit(true);
        	s.close();
        	con.close();
        	}catch(Exception e){
        	System.out.println("ERROR: "+e.getMessage());
        	}
        	}
    	
    	return null;
    }

}

Open in new window


The problem is with the public void InsertValue it says that "void is an invalid type for the variable InsertValue".
I think my issue is released this this

https://stackoverflow.com/questions/16119650/why-oracle-driver-is-needed-in-eclipse-build-path

I'm just starting learning java and Eclipse, so all of this stuff is new to me.  
Is someone able to explain to me what I need to do with a dependency of jar files and classpath ?
ASKER CERTIFIED SOLUTION
Avatar of girionis
girionis
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial