Connecting Java web app to a MySQL database RRS feed

  • Question

  • I have a Java web app, which I have developed and deployed locally on my PC. The application uses jsp files, as well as java servlets. The database is created using phpMyAdmin. Now I want to make this app available online so as other people can use it. To do so, I've created an Azure web app and I deployed my JAVA app to it using war file. the problem is that I can't connect to the database. I tried to create a database using "My sql inApp" option. My questions are:
    1. Is "web app" the correct Azure service to use for the described purpose?
    2. I've created a database using "Mysql In App" option. However, I couldn't connect it to my java application. The application shows the first page, but it doesn't present anything for the next page. for the data connection, my original code is connected to the local database using the getConnection method of the DriverManager class.

    My local environment is Java 13, Apache Tomcat 9, and phpMyAdmin

    Wednesday, April 29, 2020 9:04 AM

All replies

  • Hi Alaa,

    We're migrating from MSDN to Microsoft Q&A as our new forums and Web Apps which is your question is more closely related to has already made the move! In future, you can ask and look for the discussion for Web App related questions here: https://docs.microsoft.com/answers/topics/azure-webapps.html. We are actively working to onboard remaining Azure services on Microsoft Q&A and we will make a public announcement once complete. Want to Learn more about new platform: Microsoft Q&A Getting Started.

    Having said that, a web app is the correct Azure service to host your Java web app. MySql In App, on the other hand not the best option for production load. Not sure if you came across this announcement but it covers some of the limitations of MySQL In App. You add MySQL In App to your app service, you can utilize MYSQLCONNSTR_localdb environment variable or open D:\home\data\mysql\MYSQLCONNSTR_localdb.ini from the kudu console to get the connection string. The best option would be to use a separate MySQL database hosted in Azure. Checkout https://docs.microsoft.com/en-us/azure/mysql/overview for an overview and detailed infromation.

    Hope this helps.

    Thanks in advance, Ryan

    Thursday, April 30, 2020 10:42 PM
  • Hi Ryan,

    Thank you for your reply.

    Actually, my app is not too big and there is no heavy transactions on it. So, I think MySQL In app is enough.

    You mentioned that I can utilize MYSQLCONNSTR_localdb environment variable or open D:\home\data\mysql\MYSQLCONNSTR_localdb.ini . Can you please explain this further. I already saw this data but I couldn't figure out how can I use them. Particularly, what should I change in my code to make it ready to use this database. My original code use the following lines of code to connect to my local db:


    Connection connect = DriverManager.getConnection("jdbc:mysql://localhost:3306/mydb", "root", "");

    Can you please give me steps on how to change the connection? Also, should I make these changes locally (before publishing the war file to Azure)?

    Thanks again 

    Friday, May 1, 2020 5:21 AM
  • Hi Alaa,

    I replied to your Q&A post. Check it out.

    Thanks in advance, Ryan

    Friday, May 1, 2020 9:53 PM