Please I have a Java Desktop app which connects to a MySQL database and I would like to run the application over a network.
This is what I've done so far.
My Java application generates a batch file that points to the original local of the .jar file so I simply place this batch file in other client systems and run them so they simply find the .jar file on the server system and open the application.
But I have an issue, I have a scenario where I don't know the server's system name so I can't specify it in the MySQL database connection string.
Please how can I dynamically get the system name and pass it into the database connection string so the client systems can also connect to the same server or database?
you may find it useful if you want to know how could we get username of any host System.getProperty("user.name") returns HOSTNAME instead of currently logged username
This may help you
import java.net.InetAddress;
Code
String myip=(InetAddress.getLocalHost()).toString();
Here you will get pc name and ip address with a '/' separated
String data[]=myip.split("/");
System.out.println(data[0]); // Machine name
System.out.println(data[1]); //Ip address
Related
What the title says, basically. I have created a program for managing a database, and it worked perfectly inside and outside of the Netbeans IDE. However, as soon as I move it to another computer it can't access the database anymore. I don't know what the problem is, both computers are on the same LAN so they should be able to access the same localhost.
Your url is:
jdbc:mysql://localhost:3306/javabase
localhost is only valid on your local computer. If you want to access a database on another computer you have to use the hostname or the IP address of this computer.
For example:
jdbc:mysql://192.168.0.110:3306/javabase
How to update an MDB file from other machines remotely over the HTTP?
I have 2 machines that are connected by the internet, on the first, I have an MDB file and on the other, I have a java web application, I want to send an SQL query from the java web application to update the MDB file on the other machine over the HTTP.
I tried to use FTP, but it is transferring the whole file b
A file such as word, or power-point or Access?
Well, a horse is a horse is a horse.
A file is a file is a file.
You don't connect to a word file to update it. You don't connect to a Excel file, or a power-point file. And you don't connect to a Access file. You OPEN a file, and THEN modify it. You can't open nor modify files over FTP, nor can you modify them over HTTP either. And you can't even do that with a plane jane text file. These are files - you have to open them to modify them. Or pull a whole copy to one side. Update that file, and then send it back.
So, you don't want to confuse the concept of a simple file, or file based system like say a text file, excel file, or Access file. These are NOT servers or say a service that you connect to. You never open a MySQL file - you connect to a server + service via tc/ip (a socket conneciton) and then send commands back and forth. You NEVER open or touch that MySQL data file. The server updates that file - not you, and not your code.
So, Access is not a server based, or socket connection based service. It is a file based system - not un-like a text file. You don't connect to a text file, you HAVE to open that file - modify it and then save it. You can't do that over http. In fact you can't even do that with FTP either. You can pull the whole file, modify and then send it back to where you got that file from.
Now, you could however setup + create some web service calls or entry points on the one site. You could send that web site some commands, and then code behind on that web site can open up that text file, word file, or in this case the Access file and make changes . But once again, just like MYSQL or say the web server? You not opening the remote file direct - are you? You are (and can) thus setup some code or web methods (even REST ones) that accept commands, and those (even sql update commands) could then be run by that remote server/service and thus update the file on that target system. In the case of Access data files?
If you look VERY close, even a ODBC connection string ALWAYS ALWAYS resolves to a valid windows path name (and a full legal qualified windows path name at that).
so, while there is a ODBC driver, the software driver still in fact uses a standard windows OS file open command against that plane jane file sitting in the hard disk. So to update that Access file, you need the driver - since it knows how to open that file, and how to update the delicate data file structures inside. So, even via ODBC? Well, it not a socket connection and you not connecting to a server on the other end - but in fact opening a simple windows file. In fact this means that you not only require DIRECT file rights to that access data file - but you actually need the windows file system!
However, sqLite is the SAME thing. There are thus some jdbc drivers. This JDBC concept is VERY similar to ODBC, but is for web based systems. You install a library on one end (where sqlite resides), and then that web service can take your sql commands (updates or query pulls), and thus the web site code now opens that local file, executes sql against it, or does a query pull , and then returns the results of your query - and the web query calls are done via that web service (rest calls) on that server. So, you can in theory shuffle commands between two web servers - and there are some types of "drivers" such as jDBC standards that in theory do wind up giving you a similar experience to ODBC.
we just started learning about sql statements and such, and right now i am totally confused on how to do this:
I need to access the database of another computer (we are using mysql workbench) using java codes
What i have done so far:
grant all privileges using '%'
i can already connect to the database (mysql) in my own computer (java codes and jdbc)
my problems are:
what are the steps do i need to do to be able to access the database from another computer, there are no direct answers in google...and now i am totally confused on how to do this because every site keep on telling me about cpanel, which i dont know how to have one...then this remote access that requires me to change my sql server configuration, i dont know how to find this...
CAN SOMEONE GIVE ME A STEP BY STEP SETTING/SETUP i need to do, to be able to access the database/connection from another computer? i only need the Normal steps, no need for safety/security setups and descriptive steps, i can do the rest of specific research on Google
SOLUTION
Hey Just configure that system IP in the JDBC connection call then you will be able top connect and retrieve the data in the Java Layer.
String DB_URL = "jdbc:mysql://localhost/EMP";
String USER = "username";
String PASS = "password";
Connection conn = DriverManager.getConnection(DB_URL,USER,PASS);
Instead of "localhost" give your destination MySQL system IP address.
Just run the the mysql in one device then get that device Ip address, then on the other device use the http://IPADDRESS:8081/yourWebsite
for example instead of
instead of http://localhost:8081/yourWebsite = http://271.1.1.10:8081/yourWebsite
it will work from there, not need to configure anything. the other device will be using the same project and same database
note both devices should be on the same network
am getting started with Java database development and i wanted to know how to create and use database outside of the Derby server so for example instead of using this as a host url :
String host = "jdbc:derby://localhost:1527/Employees";
i want to use something like this :
String host = "jdbc:derby://c:/MyDb/Employees";
i dunno if that is correct or not, but this is what am trying to do cause i don't know how to use the database in the localhost after exporting the executable jar for the application
thank you
If you want to load database from the file system, you use:
String host = "jdbc:derby:c:/MyDb/Employees";
See the examples.
I'm new to android programming so please I need your help
I want to make a mobile application that connects to a databse on my laptop through internet without configuring my router
I'm using phpmyadmin in which i created a database, and I made a file called login.php that can make sure of username and password from database
I enabled the port 80 in firewall
now i wrote in eclipse this url : http:"//192.168.1.3:80/Day%20Manager/Login.php"
the ip address is optained by writing ipconfig in cmd and getting the IPV4 address
well it's not working it's giving me NetworkOnMainThreadException
can you help me please
Have a look at this link. This might help. Ofcourse if you are going to need to access it from your application you would have to provide an intermediary php script to get it working correctly.
you said you are using phpmyadmin database, then place your php file in c:/>xampp/htdocs folder, open your browser and enter localhost/login.php then you will get output, in the same way connect to url from program then you will get the data.
note: make sure internet permission in manifest file.