Connecting to MySql through JDBC

201 views
Skip to first unread message

Wesley Hilebrand

unread,
Sep 30, 2015, 2:58:06 PM9/30/15
to jPOS Users
Hi everybody,

First off, I am newbie to jPOS and Q2.

I would like to connect to database mysql using JDBC. I have found a way to connect mysql using Hibernate, as documented here on page 15. But I don't want use it.

After several searches, I only found out the following posted by Alejandro Revilla, but how can I use it on my class below? Can you give me an example?

I appreciate your help.

public class IncomingMessageListener implements ISORequestListener {
   
@Override
   
public boolean process(ISOSource source, ISOMsg m) {
       
ISOMsg response = new ISOMsg();
       
       
/*
            store m in database
        */

       
       
try {
            response
.setMTI("0810");
            response
.set(7, m.getString(7));
            response
.set(11, m.getString(11));
            response
.set(12, m.getString(12));
            response
.set(13, m.getString(13));
            response
.set(39, "00");
            response
.set(42, m.getString(42));
            response
.set(70, m.getString(70));
            response
.set(123, m.getString(123));
            response
.set(124, "00822222222");
            response
.set(127, "009000000005");
            source
.send(response);
       
} catch (ISOException ex) {
       
} catch (IOException ex) {
       
}
       
return false;
   
}
}

Victor Salaman

unread,
Sep 30, 2015, 3:23:07 PM9/30/15
to jpos-...@googlegroups.com

--
--
jPOS is licensed under AGPL - free for community usage for your open-source project. Licenses are also available for commercial usage. Please support jPOS, contact: sa...@jpos.org
 
Join us in IRC at http://webchat.freenode.net/?channels=jpos
 
You received this message because you are subscribed to the "jPOS Users" group.
Please see http://jpos.org/wiki/JPOS_Mailing_List_Readme_first
To post to this group, send email to jpos-...@googlegroups.com
To unsubscribe, send email to jpos-users+...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/jpos-users
---
You received this message because you are subscribed to the Google Groups "jPOS Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jpos-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jpos-users/6b1b16b8-1610-4780-98f9-26d4b8d91f5b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Wesley Hilebrand

unread,
Sep 30, 2015, 3:55:21 PM9/30/15
to jPOS Users
Thanks Victor,

I've seen the class PersistentEngine.java, which basically creates the JDBC connection, such as shown in the link posted by you. 
Also, ConnectionPool.java seems more interesting since it manages all connections.

Best regards,

chhil

unread,
Sep 30, 2015, 4:06:36 PM9/30/15
to jpos-...@googlegroups.com
At a very basic level....
You could implement a qbean that implements your db access using jdbc.

But as a qbean and has a connection getter method.

If you need pooling you would need to implement it.

Register this qbean in the NameRegistrar.

Wherever you need to do some DB work, get the DB object from the nameregistrar, get the connection and do what you need to do.

-chhil

Victor Salaman

unread,
Sep 30, 2015, 4:12:40 PM9/30/15
to jpos-...@googlegroups.com
chhil, I think you lost him :)

chhil

unread,
Sep 30, 2015, 4:18:57 PM9/30/15
to jpos-...@googlegroups.com
From the initial code that was posted, some beans are already in play, so I added one more.
If Wesley wants to take the tougher jdbc route, jpos wont stop him. Just want to make sure he is aware that it can be done.

You are always here to answer questions :)


-chhil

Victor Salaman

unread,
Sep 30, 2015, 4:26:24 PM9/30/15
to jpos-...@googlegroups.com
Chhil:

Chill, my point was in the lines of "jPOS-EE provides battle-tested components/patterns which provide excellent performance at very little cost to the developer", but Wesley for some reason wants to re-invent the wheel and I have very little energy left to stop someone from shooting themselves. :)

/V

Alejandro Revilla

unread,
Sep 30, 2015, 4:49:00 PM9/30/15
to jPOS Users
Wesley, 

The PersistentEngine is kind of old and deprecated stuff, it's there just for backward compatibility. I don't recommend to use it for new code.

If you don't want to use Hibernate (I love/hate it myself) you could try http://www.jooq.org/

You can also use bare bones JDBC and create your own SQL, or better yet, use a connection pool such as c3p0.

Bharavi (a long time jPOS developer from the early days) recently recommended me https://github.com/brettwooldridge/HikariCP - I didn't have time to test it yet, but he says it's working very well for him in production.

Hope this helps.



Wesley Hilebrand

unread,
Sep 30, 2015, 5:06:11 PM9/30/15
to jPOS Users
Thanks Chhil, Victor and Alejandro,

I feel very satisfied to your suggestions. It would be great to implement Chhil's suggestion, but I must learn much more of jPOS and I don't have too much time in my project.

Victor, I will re-think to use hibernate, since it is ready-to-use.

Alejandro, thanks for your help. I will check those alternatives. 

Best regards,
Reply all
Reply to author
Forward
0 new messages