To get this to work you need to do a few things:
If you want to use a different database, then you can add a new resource to the conf/Catalina/localhost/ROOT.xml file. If you want to use the dotCMS database to host the additional tables then you can skip this step.
From within your java code you can get a database connection using the DbConnectionFactory class. Now you can read the data from the database. Here's an example: import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement;
Connection conn = DbConnectionFactory.getConnection(); Statement selectStatement; try { selectStatement = conn.createStatement(); try { selectStatement.execute("SELECT * FROM your_table WHERE your_where_clause etc..."); ResultSet result = selectStatement.getResultSet(); if (result.next()) { .. do your stuff here... // for example: // Long dbId = result.getLong("Id"); // String stringField = result.getString("stringFieldName"); // int intField = result.getInt("intFieldName"); } finally { selectStatement.close(); } } catch (SQLException e1) { // Log the error here }
}
If you want to use this data in velocity you'll need to create a viewtool. Read more about that here: http://dotcms.com/docs/latest/DynamicPluginsViewtool