usingdatabaseserversinmistudio

This example will show you how to read and write a value to a database table in MIStudio. This example uses SQLite, which is built into MIStudio with the JDBC driver needed for the database. This example can be extended to any JDBC database but you will need to have this database set up and (very importantly) add the JDBC driver jar to the “drivers” node of the MIStudio project by right clicking on the drivers node and browsing for the JDBC driver jar downloaded on your computer system.

Preparation

Start MIStudio and a new project. Add a Button and an Annunciator to the Design Window. These will be used later to trigger the database read and write. Copy both of these to the Diagram Window.

Step One: Set up the Database Connection

This example uses SQLite. With the Diagram Window visible, add a SQLiteConnectionManager from the Database tab to the Diagram Window. The SQLiteConnectionManager needs a database name. Enter “test.sqlite” in the Database Name property. You do not need to enter a User Name or Password for SQLite.

Step Two: Create the Table

To enable reading and writing to the database, MIStudio must be put into LIVE mode. Toggle the “SIM” button on the top menu bar until it says “LIVE”.

The first step is to create the table called “test”. This can be done with DB Browser for SQLite or can be done in MIStudio. The CREATE statement to make a table called “test” with one column called “value” of type INT is:

CREATE 'test' ('value' INT);
  • usingdatabaseserversinmistudio.txt
  • Last modified: 2021/07/28 13:55
  • by wikiadmin