WebMethods JDBC Connection

Hi All
Good Morning . I’m sorry; i know that, i have Select wrong “Forum” . I don’t find webMethods JDBC .

Anyway.,
I’m trying to create Java Service to create JDBC Connection and return as a connection Object So that I can re-use the same connection in the entire service where ever i want then end of the service i like to invoke another Java Service with Connection as Input so i can close JDBC connection .

I have attached simple java JDBC code . which i’m trying to achieve it.

I’m getting the following error. When I’m trying to return the “Connection” as output ; Can any one can suggest me…

Could not run ‘connect’
java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: java.lang.Object

java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: java.lang.Object
at com.wm.util.coder.IDataBinCoder.doJavaSerializationDecode(IDataBinCoder.java:1142)

Note:
I’m trying not to use JDBC Adapter.

Thanks
J

WEBMETHODSJAVA.txt (611 Bytes)

Use the below code snippet which works for Oracle and do the changes for MySQL

Make sure to import the JDBC driver to your package or java project.

import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.SQLException;

IDataCursor pipelineCursor = pipeline.getCursor();
		
		Connection jdbcConnection = null;
		
		try {
			
		    Class.forName("oracle.jdbc.driver.OracleDriver");
		
		} catch (ClassNotFoundException e) {
		
		  
		    e.printStackTrace();
		    return;
		
		}
		
		try {
			
		    jdbcConnection = DriverManager.getConnection(
		            "jdbc:oracle:thin:@localhost:1521:xe", "system", "manage");
		
		}
		
		catch (SQLException e) {
			
		  
		    e.printStackTrace();
		    return;
		
		}
		
		
		if (jdbcConnection != null) {
		    System.out.println("Connected to DB");
		} else {
		    System.out.println("Failed to make connection");
		}
		
		IDataUtil.put( pipelineCursor, "jdbcConnection", jdbcConnection );
		pipelineCursor.destroy();

You have to write the custom code for connection management and pooling. May I know why you are not using the WmJDBC Adapter?

Thanks Mahesh for your reply.

I’m was coded exactly same code . Please find attached file but not sure why its returning the following error. Is your code working without any errors?

Could not run ‘connect’
java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: java.lang.Object

Regarding your question :. Please find my answer ***
You have to write the custom code for connection management and pooling. May I know why you are not using the WmJDBC Adapter?
*** Some times in one service we perform multiple (more than 4 ot 5 ) transaction not just insert … we perform many other sql transactions like execute procedure, select , insert etc.,

 So performance wise i thought of open connection and perform all kind transaction required then finally i can close connection..

Thanks
Jana
jroq8295@gmail.com
WEBMETHODSJAVA.txt (1.36 KB)

The code that is attached in the previous thread works fine without any issues and after execution I can see a session gets created for the user. I ran this service on 9.12 integration server. Both the server and dB are hosted locally to my laptop.

Check on your side if there is any network connectivity issues and to answer your question regarding the transaction handling, WmJdbc adapter supports this in conjunction with WmArt package. Quickly refer the documentation and let us know if you have any questions.