How to connect to a local mysql database on webswing? [duplicate] - java

This question already has answers here:
Connect Java to a MySQL database
(14 answers)
Closed 6 months ago.
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.

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

JPA to MS SQL Server via Eclipse: Ping Failed [duplicate]

This question already has answers here:
JDBC connection failed, error: TCP/IP connection to host failed
(9 answers)
Closed 5 years ago.
I have a local MS SQL Server Express 2016 running on 1433. I can connect to it via MS SQL Management Studio and HeidiSQL just fine.
In Eclipse Neon I created a new JPA project. I want to create entities from my DB. So I click on JPA Tools -> Generate Entities from Tables.... In the following dialog window I click on the Add connections... icon. By searching the internet I found two different approaches for continuing from here:
a) Connection Profile Type: SQL Server
b) Connection Profile Type: Generic JDBC
a) In the following window I add a new driver, specify the path to my sqljdbc42.jar and set all the properties (Driver Class: com.microsoft.sqlserver.jdbc.SQLServerDriver). The weird thing, when I chose this driver, in the Properties section nothing shows up and I get the following error:
b) Similar to a) I add a new driver, specify the path to the jar file and set all the properties. This time I get one step further: I can press the Test Connection button. If I do so however, the window freezes for a few seconds and then shows a Ping failed! error.
I guess the URL is wrong so I tried a lot of different variations but none of them worked. Here are a few of them (but I tried many more):
jdbc:sqlserver://MyPcName\SQLEXPRESS:1433
jdbc:sqlserver://MyPcName\SQLEXPRESS
jdbc:sqlserver://MyPcName\SQLEXPRESS:1433
jdbc:sqlserver://MyPcName\SQLEXPRESS
jdbc:sqlserver://localhost:1433
jdbc:sqlserver://MyPcName\SQLEXPRESS:1433;DatabaseName=MyDb
As mentioned above, connecting via Management Studio or HeidiSQL works (with the username test and no password). And while it should not matter since the server is running locally I tried turning of the firewall and it did not help either.
I still don't know why a) does not work but I figured out my issue with b). MS SQL Management Studio and HeidiSQL did connect to the database via named-pipe instead of tcp and the tcp connection was not actually setup. Following the steps in this answer solved it:
https://stackoverflow.com/a/24299346/4961688

Missing Oracle Database connection Driver when running on an external host

When running the Java web service I'm building on Local Host, everything runs smoothly, however when I attempt to run the exact same code on a different host, such as on AWS, it fails.
I have narrowed the cause down to the fact that the database connection driver "oracle.jdbc.driver.OracleDriver" is absent when the application is not hosted locally, which means that the SQL queries are failing to execute for the obvious reason that they aren't being sent anywhere since the connection is failing to open.
How do I build my project such that the driver is included? Everything else should be fine as it runs as expected on localhost, however I can't run the web service locally, it isn't an option.
You should consider the way you are deploying your webservice. I will give you a checklist, so make sure everything is done.
Insert the oracle jdbc driver inside the libraries folder on your app -- you should consider java jvm version you are running, since your deployment environment may be different from your dev/testing environment;
2nd option: insert the oracle jdbc driver inside your container or application server libraries folder;
Add to your $CLASSPATH or %CLASSPATH% environment variable the right option for your oracle jdbc driver

Accessing MySQL Database on XAMPP From a Remote Machine

I am trying to access a my MySQL database thorugh a program I have written that is currently being stored and run on XAMPP on my local machine. I'd like to connect to it from a different machine that is on the same network so they can access the database read/write etc. I am however having no luck in connecting. I've packaged the Java program into an exe that I am running on the remote machine. I've tried a number of solutions already;
I've created a user in PHPMyAdmin that can connect from any host, and has all priveleges granted on the database in question.
I've edited my program for the remote machine so that "jdbc:mysql://localhost/sdcjobs"; is now "jdbc:mysql://(theipaddressofmymachine)/sdcjobs";
I've edited my ini file (C:\xampp\mysql\bin\my.ini) so that bind address is uncommented as now bind-address=0.0.0.0
One of the main question marks for me is what software needs to be installed on the remote machine. On my machine (the one thats running the server) I have XAMPP installed that is running an Apache server and a MySQL database. On the remote machine I've installed nothing aside from my Java program, does the remote machine also need MySQL installing on it?
Have you tried to connect to your remote database with tools like mysql workbench or heidisql? If this does not work too, it could be a configuration issue in your my.ini
Please don't forget to restart your mysql service after changing your config.
Take a look at the mysql docu: http://dev.mysql.com/doc/refman/5.6/en/problems-connecting.html

java.sql.sqlnontransientconnectionexception: java.net.connectException : error connecting to server localhost on port

I've being working on a java project using Derbyclient (database locally hosted). I'm done with everything except that when I'm trying the desktop app while I'm not manually connected to the database (from Netbeans), the error in the title pops up and I can't seem to solve it. Thank you for taking the time to read this and help me.
Derby can be run in two modes embedded or server-based. Server-based allows multiple programs to access the same database. Embedded allows your application to run without a server. Your url selects server-based. The connection refused error indicates that the server is not running. Since the server was started within Netbeans it is shutdown when Netbeans is not running.
The options are:
Switch to embedded.
Start the server with a command outside Netbeans.
Just keep Netbeans running.
To switch to embedded see Apache's documentation for deployment options:
Eliminate the "//localhost:1527" from the url.
also see the tutorial "Run SQL using the embedded driver" at https://builds.apache.org/job/Derby-docs/lastSuccessfulBuild/artifact/trunk/out/getstart/index.html
To start the server in a seperate command window see the syntax for derbyrun.jar:
https://builds.apache.org/job/Derby-docs/lastSuccessfulBuild/artifact/trunk/out/getstart/rgsderbyrunjarsyntax.html

How to create a batch file for connecting to Java DB Network Server

I have made a Netbeans application that is reliant on the DB Network Server in order to retrieve data. In Netbeans the code works fine and runs well. Outside of Netbeans everything but the database information is working. I have made a batch file for connecting to the localhost server that seems to connect on the port I assigned: 1527. Even after connecting to the localhost, it won't display the database information.
My code in the batch file:
PATH C:\Program Files\Java\jdk1.8.0_25\db\bin;%PATH%
startNetworkServer
When I run this I get the result:
Security manager installed using the Basic server security policy.
Apache Derby Network Server - 10.10.1.8 - (1557168) started and ready to accept connections on port 1527connect
Is there more code that I need to add in order to connect to the actual database itself from the server? Or is this not the right way to do this at all? I have tried using the Embedded DB but that didn't work and only caused more problems. I would prefer greatly to stay away from it and stick to the Network DB.

Categories