Home > Enterprise >  How to connect to a local mysql database on webswing?
How to connect to a local mysql database on webswing?

Time:08-22

I am creating a java game and I need to upload it to web, I discovered the webswing that converts the jar to a web version, I tested it to jar without database connection and it worked, but when I try to connect to a mysql database it return a error:

Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/dreamland

Error into webswing executable

I am using xampp to localhost database and I don't know if it's because that it can not connect

Picture of all applications on webswing

The "jogoDreamland" application is the one that's getting the error

Configuration of "jogoDreamland"

I only modified these two, the class path I added the path to where my main class is on the project and on main class I added the package.formsLogin

The buttons that causes the errors

When I click one of these two buttons it returns the error from above, when I launch it on desktop, it runs normally and connect to the database, the problem is when I use it on webswing

mysql connector version

The connection to the database

Code that the method on the button runs, that use the db

Another code that the method on the button runs, that use the db

Currently, only these two methods are loaded when I click the button.

CodePudding user response:

At any point in time you should be aware where your application is running.

So if you run a Java Swing application on your desktop, it is running on your desktop computer. If you push this same application into WebSwing, it becomes a webapp that you have to install on some server. Via your browser you connect to that server to see the UI but it's still running on the server.

To get the database connection, the application has to connect to wherever your database is running. If you left that on the local computer, your server has to connect to the local computer. Probably it is better to install the database either on the same server or on a server close to the machine running the Webswing application.

You error message though indicates you wrapped your application but forgot to add the mysql jdbc driver.

  • Related