Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Scout » [NEON] - Working with database?
[NEON] - Working with database? [message #1728267] Fri, 01 April 2016 13:11 Go to next message
Luka Cavic is currently offline Luka CavicFriend
Messages: 47
Registered: August 2014
Member
Hello, maybe silly question, but how to work with database in Neon?

I would like to work with postgree, or mysql?

Do I need some jdbc drivers?

Is there any tutorial?

Thanks!
Re: [NEON] - Working with database? [message #1728293 is a reply to message #1728267] Fri, 01 April 2016 16:31 Go to previous messageGo to next message
Jeremie Bresson is currently offline Jeremie BressonFriend
Messages: 1252
Registered: October 2011
Senior Member
I think Matthias is working on the new version of the "MiniCRM Tutorial" => "contacts App Tutorial"

I recommend you to use the Scout additional Layer to JDBC. This way you can use the convenience SQL class as you did before the neon version (stuff like connections or transactions will be handled by Scout). You just need to add a dependency to "org.eclipse.scout.rt.server.jdbc" in the POM file of your server (see also this forum thread: [neon] AbstractSqlService)

Now that we no longer have an OSGi runtime, including a JDBC driver is much simpler. You can just take the one you need for your database from Maven Central.

The demo application "contacts" uses a Derby Database and has these dependencies declared in org.eclipse.scout.contacts.server/pom.xml:
<dependency>
  <groupId>org.eclipse.scout.rt</groupId>
  <artifactId>org.eclipse.scout.rt.server.jdbc</artifactId>
</dependency>
<dependency>
  <groupId>org.apache.derby</groupId>
  <artifactId>derby</artifactId>
</dependency>

Re: [NEON] - Working with database? [message #1728296 is a reply to message #1728293] Fri, 01 April 2016 17:28 Go to previous messageGo to next message
Luka Cavic is currently offline Luka CavicFriend
Messages: 47
Registered: August 2014
Member
Thanks for reply!

I created Abstract class

package com.rinels.epodrska.epodrska.server;

import org.eclipse.scout.rt.server.jdbc.postgresql.AbstractPostgreSqlService;
import org.eclipse.scout.rt.server.jdbc.postgresql.PostgreSqlStyle;
import org.eclipse.scout.rt.server.jdbc.style.ISqlStyle;

public abstract class PostgreeSqlService extends AbstractPostgreSqlService
{

	@Override
	protected Class<? extends ISqlStyle> getConfiguredSqlStyle() {
		return PostgreSqlStyle.class;
	}

	@Override
	  protected String getConfiguredJdbcMappingName() {
	    return "jdbc:postgresql://localhost:5432/epodrska";
	  }

	  @Override
	  protected String getConfiguredPassword() {
	    return "##hidden";
	  }

	  @Override
	  protected String getConfiguredUsername() {
	    return "##hidden";
	  }
}



than, i my etc UsersService I extend this class...

but I have this error that class is not found

Caused by: java.lang.ClassNotFoundException: org.postgresql.Driver
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.eclipse.scout.rt.server.jdbc.internal.pool.SqlConnectionBuilder.createJdbcConnection(SqlConnectionBuilder.java:36)
at org.eclipse.scout.rt.server.jdbc.internal.pool.SqlConnectionPool.leaseConnection(SqlConnectionPool.java:103)
at org.eclipse.scout.rt.server.jdbc.AbstractSqlService.leaseConnectionInternal(AbstractSqlService.java:550)
... 59 common frames omitted
Re: [NEON] - Working with database? [message #1728311 is a reply to message #1728296] Fri, 01 April 2016 19:52 Go to previous message
Jeremie Bresson is currently offline Jeremie BressonFriend
Messages: 1252
Registered: October 2011
Senior Member
This looks like a good start.

A google search "org.postgresql.Driver maven dependency" pointed me to this page: PostgreSQL JDBC Driver.
I did not test it, but I think you should declare those dependencies:
<dependency>
  <groupId>org.eclipse.scout.rt</groupId>
  <artifactId>org.eclipse.scout.rt.server.jdbc</artifactId>
</dependency>
<dependency>
  <groupId>postgresql</groupId>
  <artifactId>postgresql</artifactId>
  <version>9.1-901-1.jdbc4</version>
</dependency>

I think that you needs to select the version compatible with your database version. For this example I took the latest version ("9.1-901-1.jdbc4").

----

I think you should add an order annotation "@Order(1000)" on top of your service.

You can read more about the Bean Manager in our Architecture document (in particular the section "3.4.1" about the order annotation and the ranges that makes sense).
Previous Topic:[NEON] Reloading tabular data using F5 loads data twice
Next Topic:[neon] Suggestion for JEE conform login procedure
Goto Forum:
  


Current Time: Fri Apr 19 08:49:08 GMT 2024

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

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

Back to the top