Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Kura » Connect HSQL Database
Connect HSQL Database [message #1728373] Mon, 04 April 2016 04:03 Go to next message
David Nguyen is currently offline David NguyenFriend
Messages: 13
Registered: March 2016
Junior Member
Hi everyone,

Today, I have a project and It need connect to HSQLDB on Kura gateway to store data. But I can't find any example to show how to connect with database server although Kura provided some API to connect to HSQLDB in class "org.eclipse.kura.db".
Can anyone help me to solve this problem?

Thank you and best regards.

[Updated on: Mon, 04 April 2016 06:59]

Report message to a moderator

Re: Connect HSQL Database [message #1728405 is a reply to message #1728373] Mon, 04 April 2016 08:38 Go to previous messageGo to next message
Benjamin Cabé is currently offline Benjamin CabéFriend
Messages: 201
Registered: July 2009
Location: Toulouse, France
Senior Member

Hi David,

You should write a component that consumes the DbService.
You can look at how the Kura Datastore is implemented (see org.eclipse.kura.core.data.store.DbDataStore), ie how it uses the DbService to retrieve a JDBC connection, create tables, execute queries, etc.


Re: Connect HSQL Database [message #1728425 is a reply to message #1728405] Mon, 04 April 2016 10:04 Go to previous messageGo to next message
David Nguyen is currently offline David NguyenFriend
Messages: 13
Registered: March 2016
Junior Member
Hi Benjamin,

Thank you for your support. My project is editing directly in project org.eclipse.kura.web and I have a problem when I try to instance an object of DbService to connect database. I also have tried to connect database like HsqlDbServiceImpl class, but It didn't work Sad.

 try {
	DriverManager.registerDriver( new org.hsqldb.jdbcDriver());
}
catch (SQLException e) {
	throw new RuntimeException(e);
}

Maven can't compiler when I try to add them in project org.eclipse.kura.web.

May you explain your way to connect to database with kura.

[Updated on: Mon, 04 April 2016 10:09]

Report message to a moderator

Re: Connect HSQL Database [message #1728464 is a reply to message #1728425] Mon, 04 April 2016 14:20 Go to previous messageGo to next message
David Woodard is currently offline David WoodardFriend
Messages: 420
Registered: July 2014
Senior Member
Hi David,

What problem were you having in using the DbService in the web bundle? You have to make sure you are consuming the service from the server code, not client code. You will likely need to follow the GWT RPC solutions as currently used in Kura [1][2].

[1] https://github.com/eclipse/kura/tree/develop/kura/org.eclipse.kura.web/src/main/java/org/eclipse/kura/web/shared/service
[2] https://github.com/eclipse/kura/blob/develop/kura/org.eclipse.kura.web/src/main/java/org/eclipse/kura/web/server/GwtSecurityServiceImpl.java

Thanks,
--Dave
Re: Connect HSQL Database [message #1728525 is a reply to message #1728464] Tue, 05 April 2016 07:37 Go to previous messageGo to next message
David Nguyen is currently offline David NguyenFriend
Messages: 13
Registered: March 2016
Junior Member
Hi David Woodard,

Thank you very much. I have solved my issue. Very Happy
Re: Connect HSQL Database [message #1749979 is a reply to message #1728525] Wed, 14 December 2016 17:13 Go to previous messageGo to next message
Kat Kat is currently offline Kat KatFriend
Messages: 3
Registered: December 2016
Junior Member
Hi David N and David W,

Would you mind sharing the code to connect to the database? The above links are dead, and I tried importing org.eclipse.dB but had dependency issues when compiling in eclipse. Also tried embedding sqlite in a bundle but that failed at deployment as well. Thanks.

Kat
Re: Connect HSQL Database [message #1750088 is a reply to message #1749979] Fri, 16 December 2016 00:31 Go to previous messageGo to next message
Kat Kat is currently offline Kat KatFriend
Messages: 3
Registered: December 2016
Junior Member
I was following the example of DbDataStore as suggested. I see it received DbService from DataServiceImpl, which in turn got it through public void setDbService(DbService dbService). But how to specify its dependency on org.eclipse.kura.db.DbService ? The statement in my program "import org.eclipse.kura.db.DbService;" caused compile error as it can not be resolved.

FYI, I downloaded Kura workspace file and loaded it so that the demo programs worked. But for this particular usage of Db service, how to specify the dependency?

Thanks for any tips. I'm new to Java/Eclipse and Kura, and this all seems rather confusing.
Re: Connect HSQL Database [message #1750173 is a reply to message #1750088] Fri, 16 December 2016 17:52 Go to previous messageGo to next message
David Woodard is currently offline David WoodardFriend
Messages: 420
Registered: July 2014
Senior Member
Hi Kat,

Did you import the desired package in your bundle's MANIFEST.MF file? If you plan on using the DBService, you will also need to declare a reference in your component XML. You can see how the DataService is doing this here [1][2].

[1] https://github.com/eclipse/kura/blob/develop/kura/org.eclipse.kura.core/META-INF/MANIFEST.MF
[2] https://github.com/eclipse/kura/blob/develop/kura/org.eclipse.kura.core/OSGI-INF/data.xml

Thanks,
--Dave
Re: Connect HSQL Database [message #1750184 is a reply to message #1750173] Fri, 16 December 2016 23:04 Go to previous messageGo to next message
Kat Kat is currently offline Kat KatFriend
Messages: 3
Registered: December 2016
Junior Member
Thanks Dave. I finally figured out how to do it by importing the desired package. Those dependency things are really not obvious to newbies.
Re: Connect HSQL Database [message #1750328 is a reply to message #1750184] Tue, 20 December 2016 02:00 Go to previous message
David Woodard is currently offline David WoodardFriend
Messages: 420
Registered: July 2014
Senior Member
Glad you figured it out. OSGi, like most things, takes a little time to figure out. Once you have used it a few times you will likely find that it is not too bad, and more importantly, it can be quite powerful.

--Dave
Previous Topic:Bundles with libraries
Next Topic:Getting properties changes from broker via MQTT
Goto Forum:
  


Current Time: Thu Apr 25 22:54:45 GMT 2024

Powered by FUDForum. Page generated in 0.03879 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top