How can I view the contents of the local SQLite database?

Hi, Iā€™m currently working on lesson 5.2.3 - ā€œPreparing an Environment for Automationā€ of the intermediate certificate in test automation. I have created the docker-compose.yml file and have run the app as per instructions. Timesheet.db file is present both locally and in the docker, Iā€™m able to add a new project via the front end and the changes appear to be retained. However, Iā€™m struggling to open the timesheet.db file to review my changes as per step 4: " 1. Finally, we can open the local SQLite database in our project using a database manager (I like the SQLite extension for VSCode) and we can query the database to confirm that the local database has been updated." I tried using IntelliJ with the default DB browsing features as well as a plugin called SimpleSQLiteBrowser. In all cases, no tables are identified within the file so it seems like the issue might lie with the yaml file setup rather than the plugins?

I noticed that the contents of the yml file refer to c sharp version rather than the java Iā€™m using in line image: ā€œministryoftesting/support-app-c-sharp:latestā€ so I changed it to ā€œsupport-app-javaā€, also moved the line ā€˜appā€™ to the right as it was aligned left and did not seem to use the correct yml format. Still, no luck.

Could anyone please advise what might be the issue here or what am I doing wrong?

2 Likes

Hi @krisl

Iā€™ve looked into this and it appears somehow the content for the C# version of lesson 5.2.3 has been added to this lesson when it should have been Java version. Iā€™ve let @sarahdeery know and the correct lesson will be put in place shortly. Apologies again and thank you for raising it.

3 Likes

Hi @krisl

That lesson has been updated now. Thanks for posting about the issue.

Iā€™m sorry that error slowed down your progress. Let us know if you have any more problems.

Best,

Sarah

2 Likes

Thank you both.

I followed the updated process, however I still donā€™t seem to be able to access the data in the db. Do I assume correctly that upon connection I should be able to view the tables created by the db.sql script? While technically it appears that I can open the connection to the h2 db, it contains no tables. However, data appears to be preserved, so it seems like there is a connection issue somewhere.

While the docker logs show that port 9090 is opened as expected, I believe that there could be an issue in the BaseBD class and tcp server creation?

1 Like

Hi,

Can you share with me the connection details youā€™ve used as well as the tooling youā€™re using to connect to the DB.

1 Like

Hi Mark, sorry for the delayed response. I used the database plugin in intellij Idea Ultimate, with the credentials as displayed on the attached screenshot (ā€˜passwordā€™ was used as the password, I also tried leaving both user and pw boxes empty).


1 Like

That all looks correct to me. And to confirm you have set the following environmental variable?

dbServer=true

1 Like

Thatā€™s right, I added the following line to my Dockerfile

ENV dbServer=true

1 Like

Iā€™m not sure as to why this wouldnā€™t work for you then. Are you able to share your repository and I can take a look at your work and see whatā€™s happening.

Thanks Mark, my repository can be found here:

So Iā€™ve taken a look at your code and I think the problem is on lines 32 and 33 in BaseDB.java. The code block is:

connection = ds.getConnection();
executeSqlFile("db.sql");
executeSqlFile("seed.sql");

Server.createTcpServer("-tcp", "-tcpAllowOthers", "-tcpPort", "9090").start();
logger.info("create server code was executed");
if(System.getenv("dbServer").equals("true")){
    Server.createTcpServer("-tcpPort", "9090", "-tcpAllowOthers").start();
    logger.info("create server code was executed");
}

When you set dbServer to true in your Dockerfile youā€™re allowing the Server.createTcpServer to be called twice. The problem with this is that when it runs the second time it falls over because a connection has already been opened from the first time you ran createTcpServer. This in turn causes the whole app to fall over. However, you wonā€™t see that itā€™s fallen over when running docker unless you check the docker logs.

So I suggest you delete lines 32 and 33 and then try again. Hopefully the app should start up again and then you will be able to connect to the DB.