Skip to content

Commit 2e97ad5

Browse files
STAND-131: Fix java.sql.SQLSyntaxErrorException: Unknown column 'RESERVED' in 'WHERE' in 3.x Standalone (#89)
* STAND-131: Fix java.sql.SQLSyntaxErrorException: Unknown column 'RESERVED' in 'WHERE' in 3.x Standalone * Use 2.8.1-SNAPSHOT+ with mariadb support * Updated title from Openmrs 3.x to O3 RefApp v3.x * remove repititions
1 parent e4c0929 commit 2e97ad5

File tree

9 files changed

+33
-20
lines changed

9 files changed

+33
-20
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ NOTE: Without this folder structure, you will get errors while trying to run the
116116

117117
## DATABASE CONNECTION STRING
118118

119-
jdbc:mysql://127.0.0.1:3316/openmrs?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull
119+
jdbc:mariadb://127.0.0.1:3316/openmrs?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull
120120

121121
The above default database connection string has all in the openmrs mysql default database connection and is used for the MariaDB connection.
122122

pom.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<liquibase.plugin.version>4.23.2</liquibase.plugin.version>
2222

2323
<tomcat.version>9.0.106</tomcat.version>
24-
<openmrs.version>2.8.0</openmrs.version>
24+
<openmrs.version>2.8.1-SNAPSHOT</openmrs.version>
2525
<refapp.version>3.6.0-SNAPSHOT</refapp.version>
2626
<mariadb4jVersion>3.2.0</mariadb4jVersion>
2727
<junitVersion>5.12.2</junitVersion>
@@ -101,6 +101,12 @@
101101
<artifactId>mybatis</artifactId>
102102
<version>3.5.19</version>
103103
</dependency>
104+
<dependency>
105+
<groupId>org.mariadb.jdbc</groupId>
106+
<artifactId>mariadb-java-client</artifactId>
107+
<version>3.5.4</version>
108+
<scope>compile</scope>
109+
</dependency>
104110
</dependencies>
105111

106112
<build>

readme.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ splashscreen-loading.png This is the splash screen displayed on startup. It c
139139

140140
............... DATABASE CONNECTION STRING.......................
141141

142-
jdbc:mysql://127.0.0.1:3316/openmrs?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull
142+
jdbc:mariadb://127.0.0.1:3316/openmrs?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull
143143

144144
The above default database connection string has all in the openmrs mysql default database connection and is used for the MariaDB connection.
145145

src/main/config/openmrs-runtime.properties

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
module.allow_web_admin=true
44
# this connection url is copied several times in pom.xml, with the directory changed from database to emptydatabase and 3316 changed to 3326.
55
# If you change the property here, make sure to change it there too.
6-
connection.url=jdbc:mysql://127.0.0.1:3316/openmrs?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull
6+
connection.url=jdbc:mariadb://127.0.0.1:3316/openmrs?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull
77
connection.username=openmrs
88
auto_update_database=false
99
connection.password=test
@@ -12,4 +12,6 @@ application_data_directory=appdata
1212
reset_connection_password=true
1313
vm_arguments=-Xmx512m -Xms512m -XX:NewSize=128m --add-exports=java.desktop/com.apple.eawt=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED
1414
# Tell MariaDB where to find database files (this is the important part!)
15-
connection.database.data_dir=./database/data
15+
connection.database.data_dir=./database/data
16+
hibernate.connection.driver_class=org.mariadb.jdbc.Driver
17+
hibernate.dialect=org.hibernate.dialect.MariaDBDialect

src/main/java/org/openmrs/standalone/MainFrame.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ public void run() {
418418
* @see org.openmrs.standalone.UserInterface#showInitialConfig()
419419
*/
420420
public void showInitialConfig() {
421-
final JDialog configDialog = new JDialog(this, "Configure your OpenMRS " + OpenmrsUtil.REFAPP_VERSION + " Installation", true);
421+
final JDialog configDialog = new JDialog(this, "Configure your O3 RefApp v" + OpenmrsUtil.REFAPP_VERSION + " Installation", true);
422422
JPanel content = new JPanel();
423423
content.setBorder(BorderFactory.createEmptyBorder(15, 15, 15, 15));
424424
content.setLayout(new BorderLayout(10, 10)); //10,10 = hgap, vgap
@@ -427,15 +427,20 @@ public void showInitialConfig() {
427427
Font font = new Font(Font.SERIF, Font.PLAIN, 16);
428428

429429
final JButton useCurrent = new JButton("Do Not Modify the Database");
430-
430+
431431
final JButton demoDatabase = new JButton(
432-
"<html><h3>Demonstration mode</h3>Configures OpenMRS with a demonstration database. This is the quickest way to start up OpenMRS with some sample data to evaluate the system or experiment with features</html>",
433-
new ImageIcon(getClass().getResource("demonstration_mode.png")));
432+
"<html><h3>Demonstration mode</h3>Configures the application with a demonstration database. "
433+
+ "This is the quickest way to start with sample data to evaluate the system or experiment with features.</html>",
434+
new ImageIcon(getClass().getResource("demonstration_mode.png"))
435+
);
436+
434437
colorHelper(demoDatabase, new Color(136, 235, 148));
435-
438+
436439
final JButton emptyDatabase = new JButton(
437-
"<html><h3>Starter Implementation</h3>Configures OpenMRS without any patient data. If you are familiar with OpenMRS and want to start a new system, this is a good place to start.</html>",
438-
new ImageIcon(getClass().getResource("starter_impl.png")));
440+
"<html><h3>Starter Implementation</h3>Configures the application without any patient data. "
441+
+ "If you are familiar with the system and want to start a new setup, this is a good place to begin.</html>",
442+
new ImageIcon(getClass().getResource("starter_impl.png"))
443+
);
439444
colorHelper(emptyDatabase, new Color(255, 243, 136));
440445

441446
ActionListener listener = new ActionListener() {
@@ -466,7 +471,7 @@ public void actionPerformed(ActionEvent e) {
466471
}
467472

468473
JLabel instructions = new JLabel(
469-
"<html><b>Welcome to OpenMRS " + OpenmrsUtil.REFAPP_VERSION + "! OpenMRS can be configured in one of " + buttonList.size() + " ways, depending on your needs. Please click on the configuration that best meets your needs.</b><br/>(You will not see this next time you run OpenMRS)</html>");
474+
"<html><b>Welcome! O3 RefApp can be configured in one of " + buttonList.size() + " ways, depending on your needs. Please click on the configuration that best meets your needs.</b><br/>(You will not see this next time you run OpenMRS)</html>");
470475
instructions.setFont(font);
471476

472477
JButton exitButton = new JButton("Exit");

src/main/java/org/openmrs/standalone/MariaDbController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public static void startMariaDB(int port, String userPassword) throws Exception
7878
mariaDB = ReusableDB.openEmbeddedDB(mariaDBConfig.build());
7979
mariaDB.start();
8080

81-
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:" + port + "/", ROOT_USER, ROOT_PASSWORD);
81+
Connection conn = DriverManager.getConnection("jdbc:mariadb://localhost:" + port + "/", ROOT_USER, ROOT_PASSWORD);
8282
try (Statement stmt = conn.createStatement()) {
8383
stmt.execute("ALTER USER 'root'@'localhost' IDENTIFIED BY '" + ROOT_PASSWORD + "';");
8484
stmt.execute("GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION;");

src/main/java/org/openmrs/standalone/OpenmrsUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ public static void setDefaultOS(){
224224
}
225225

226226
public static String getTitle() {
227-
return "OpenMRS " + REFAPP_VERSION + " Standalone";
227+
return "O3 RefApp v" +REFAPP_VERSION + " Standalone";
228228
}
229229

230230
/**

src/main/java/org/openmrs/standalone/StandaloneUtil.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public static String setPortsAndMySqlPassword(String mariaDBPort, String tomcatP
154154

155155
String portToken = ":" + mariaDBPort + "/";
156156

157-
//in a string like this: jdbc:mysql://localhost:3316/openmrs?autoReconnect=true
157+
//in a string like this: jdbc:mariadb://localhost:3316/openmrs?autoReconnect=true
158158
//look for something like this :3316/
159159
String regex = ":[0-9]+/";
160160
Pattern pattern = Pattern.compile(regex);
@@ -330,7 +330,7 @@ public static String getContextName() {
330330
*/
331331
private static boolean setMysqlPassword(String url, String mysqlPort, String username, String newPassword) throws Exception {
332332
try {
333-
Class.forName("com.mysql.cj.jdbc.Driver").newInstance();
333+
Class.forName("org.mariadb.jdbc.Driver").newInstance();
334334

335335
MariaDbController.startMariaDB(mysqlPort, properties.getProperty("connection.password", ""));
336336

@@ -431,7 +431,7 @@ private static void updateRuntimeProperties(Map<String, String> newProps) {
431431
*/
432432
public static void startupDatabaseToCreateDefaultUser(String mariaDBPort) throws Exception {
433433
try {
434-
Class.forName("com.mysql.cj.jdbc.Driver");
434+
Class.forName("org.mariadb.jdbc.Driver");
435435
} catch (ClassNotFoundException ex) {
436436
throw new RuntimeException("Cannot find MySQL driver class", ex);
437437
}
@@ -493,7 +493,7 @@ public static String setRuntimePropertiesFileMysqlAndTomcatPorts(String mariaDBP
493493
String connectionString = properties.getProperty(KEY_CONNECTION_URL);
494494
String portToken = ":" + mariaDBPort + "/";
495495

496-
//in a string like this: jdbc:mysql://localhost:3316/openmrs?autoReconnect=true
496+
//in a string like this: jdbc:mariadb://localhost:3316/openmrs?autoReconnect=true
497497
//look for something like this :3316/
498498
String regex = ":[0-9]+/";
499499
Pattern pattern = Pattern.compile(regex);

src/test/java/org/openmrs/standalone/StandaloneUtilTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class StandaloneUtilTest {
3737

3838
private static final String USERNAME = "openmrs";
3939
private static final String MARIADB_PORT = "33126";
40-
private static final String DEFAULT_URL = "jdbc:mysql://127.0.0.1:" + MARIADB_PORT + "/" + MariaDbController.DATABASE_NAME;
40+
private static final String DEFAULT_URL = "jdbc:mariadb://127.0.0.1:" + MARIADB_PORT + "/" + MariaDbController.DATABASE_NAME;
4141

4242
private static final String MARIADB_BASEDIR_NAME = "mariadb-base-dir";
4343
private static final String DATA_DIR_NAME = "data";

0 commit comments

Comments
 (0)