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
Related
I just installed XAMPP and I'm using the control panel v3.2.1 and I have successfully created my own local MySQL database, but what I want to do, and after more than 20 google searches, I couldn't find my answer, however, I want to make my database available to the local network, so that anyone connected to my router will be able to connect and retrieve data from my MySQL server, is this possible?
And if so, can anyone link to some documentation on the matter or maybe tell me how to do so?
I have changed the bind-adress to "0.0.0.0" and I've run this query in phpmyadmin
CHANGE MASTER TO MASTER_HOST="0.0.0.0", MASTER_PORT=3306,
MASTER_USER="root", MASTER_PASSWORD="" ;
You were on the right track, but went down the wrong path somewhere along the way.
Comment out the bind-address in your my.cnf/my.ini (depending on OS). Then restart mysql so that the changes to the my.cnf/my.ini file will take affect. You can read more here at DigitalOcean. Now, anyone will be able to connect to your Mysql database remotely as long as they have proper user credentials.
So, now you want people on your local network to be able to connect. Say, your local internal network is 192.168.1.1. You can make a users for the other people on your network by executing create user 'username'#'192.168.1.%' Identified by password 'userpassword'.
The wild card (%) in the above 192.168.1.% will allow that user to connect from any of the IP's on the 192.168.1.1 network, regardless of what IP the user is allocted via DHCP. Note: If you just used the % then the user would be able to connect from any IP.
You can read more about adding users #dev.mysql.
Also in order for the user to be able to select, update, delete, etc.. data you also have to grant privileges to the user. You need to execute something like this: GRANT ALL PRIVILEGES ON *.* TO 'username'#'192.168.1.%';
You can read more about granting privileges #dev.mysql.
I'm trying to write a code where i need to keep some data in database tables.
I have learned how to use SQL. My problem is that I want this program to run on different computers while having access to the same database.
Any suggestions ?
Thanks
You'll have to run an SQL server on a computer (ie: with mySQL, SQL Server, etc.). You will run queries against the tables that are stored on this database. There are already a lot of resources online with making a database connection to a server.
Just keep database system running in a machine, and instead of pointing to localhost in your JDBC URL, point to the machine's IP Address.
I would personally recommend setting up a script on a host machine and letting it communicate with the database, and have your program communicate with the script. This way, you won't have to keep your database login credentials in your Java program, which could be dangerous.
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 am writing an application in java and i want to enable it to access a mysql remote server.
my problem is that if the application have the user name and password someone can take them and use my db with a different software.
is there a way of preventing it ?
UPDATE
i found this workaround for connecting to a remote MySQL database from an android device.
you put a service in the middle. like a php page that code the data in JSON format which the android app gets via http.
here is the example i found :
Connecting to MySQL database
Having the username and password is designed specifically to grant access to the database. That's the whole point.
You could go to some extra lengths like restricting database connectivity to specific hosts, so at least your paying customers get access to the database and no else can access it, but your customers might choose to use different software to access the database. There's no way around it except licensing terms.
What you could do is run an intermediary program on your own hardware that connects to the database and restrict access to the database to software that is under your direct administrative control. Your program would validate all requests from software under control of your customers and allow the queries that you want to allow and refuse (and log) the queries you do not have to allow. (You do not need to send raw SQL data back and forth -- you can do any amount of processing on the data and queries.)
You can setup JDBC Data Source on your application server. Here you can see example for Oracle Glassfish.
So, your credential won't be used in your code/resources.
If you are saying that you have an application trying to access a MySQL remotely (not in the same box), then i think you need not worry, as the connection that will be established by your application codes will not expose the username and password when it is trying to authenticate and authorize itself to the MySQL server.
You can limit the access to the MySQL-server so that only certain IP-addresses or IP-ranges have access to it.
As a side note, make sure that the user you use in your application only has the needed permissions to the database. For example, the user might not need to be able to create or delete tables. You can even specify permissions for the user on table and column level.
I am writing a game in Java, it is an applet. I want the user to create an account, and have it registered into a database. I know how to create a database on my computer, and do username and login checks, but how do I get the database online, so that users can login?
There are multiple ways, one is Jackcess. The examples are straight forward. An other way is to use an ODBC Jdbc driver.
I am not really sure what the applet's restrictions do have for an impact, so check this in advance. If you just need a simple data repository, think about something like SimpleDB, where you do not need an own server.