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 :)
Web ServicesXMLJava EESOAP Protocol* Tomcat

Avatar of undefined
Last Comment
girionis

8/22/2022 - Mon
girionis

What do you mean by "does not work"? Do you get any error messages?
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.
girionis

You do not need to do anything else. Are you sure your method is called?
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Mat Smith

ASKER
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 ?
girionis

Are you writing Android code? Which line has the error?
Mat Smith

ASKER
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".
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Mat Smith

ASKER
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
girionis

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question