RE: Custom SQL-Query

thumbnail
Fredi B, modified 5 Years ago. Junior Member Posts: 69 Join Date: 4/1/20 Recent Posts
Hey Liferay-Community,
So I finally got multiple React-Portlets up and running and they all get their data via REST from my REST-module. 

In one React-Portlet I am using the configuration.json to set values in the configuration_-Table (dictionary-Column).

Is there a simple way how I can access this entry now?

Like: SELECT dictionary FROM configuration_ WHERE configurationId = 'NAME-OF-MY-PORTLET'

I stumbled over  dynamicQueries but I have no clue how to adapt it to Liferay-Tables?
DynamicQuery guestbookQuery = DynamicQueryFactoryUtil.forClass(Guestbook.class, classLoader))
    .add(RestrictionsFactoryUtil.eq("name", guestbookName))
    .setProjection(ProjectionFactoryUtil.property("guestbookId"));


I just need a simple way to get some configuration-Settings (for example colorCode or title of the section) to my REST-Module.
thumbnail
Fredi B, modified 5 Years ago. Junior Member Posts: 69 Join Date: 4/1/20 Recent Posts
Solution for me that worked - but is absolutely not they way that I prefer:
Class.forName("com.mysql.cj.jdbc.Driver") ;
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/.......) ;
            Statement stmt = conn.createStatement() ;
            String query = "select dictionary from configuration_ where configurationId='PORTLET-NAME';" ;
            ResultSet rs = stmt.executeQuery(query) ;
            while ( rs.next() ) {
                    String configurationSettings = rs.getString("dictionary");
                    System.out.println(configurationSettings);
            }
thumbnail
Dominik Marks, modified 5 Years ago. Regular Member Posts: 149 Join Date: 8/29/12 Recent Posts
If you have at least something related to service builder you could make use of the custom-sql functionality (as described here: https://help.liferay.com/hc/en-us/articles/360017882012-Custom-SQL)