I'm using a java program to connect to a database created using PhpMyAdmin.
I'm using XAMPP to open mysql port: 3306.
Of course when it's closed I can't connect to the database anymore through my java program. I use the following line code to get connection.
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/"+user,root,pwd);
Is there another way to connect to a database by providing for example it's full path without having to specify the mysql port and have it running? Or are there any java classes that help to get mysql port running without using softwares as XAMPP or EasyPHP ?
Related
This question already has answers here:
How to access MySQL from a remote computer (not localhost)?
(3 answers)
Closed 7 years ago.
So I haven successfully set up a database in MySQL and can connect to it from the same laptop I set it up on with a small java program. This is fine as it is running on the local host. However, I would like to see if I could now connect to the same database from a different Laptop. The Laptops would be running on the same network.
I can only find information online about connecting with Local host and am starting to feel out of my depth.
What should I do?
Check MYSQL tutorial
Get your IP address: first You need to know what the IP address you are connecting from.
Granting Access: Granting access to a user from a remote host is fairly simple and can be accomplished from just a few steps. First you will need to login to your MySQL server as the root user.
For Linux (check this site for windows) you can do this by typing the following command:
# mysql -u root -p
mysql> GRANT ALL ON fooDatabase.* TO fooUser#'1.2.3.4' IDENTIFIED BY 'my_password';
Now you can test your connection remotely. You can access your MySQL server from another server by placing the IP instead of localhost.
Check all non-java related system properties, like firewall etc.
Test with a general MySQL client.
Replace localhost or whatever you have in the connection string with the host name or ip-address of the remote machine.
Google for jdbc connection string to find more examples.
EDIT: If you could show your current code, we may be able to help you further.
Another option without exposing your database to network and defining remote users, is to set up an ssh tunnel. You redirect one port on remote machine to mysql's local port and connect to your database like you were connecting on localhost.
Putty is a popular ssh client. For an ssh server, there are different setups based on your operating system where mysql resides.
I am currently using Netbeans 8 and trying to make the MySQL database connect to the program without downloading MySQL on to the users computer or running a server, so the MySQL file must be local. How may I proceed is there a way to package with the jar of the program or should I proceed another way.
Also here is the code that connect to the database.
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/chutesandladders", name, password);
Statement update = conn.createStatement();
It is not possible to package a MySQL "file" in JAR. MySQL always runs as a server process that you can connect to using JDBC.
The JDB URL dbc:mysql://localhost:3306/chutesandladders from your question contains the hostname localhost and the port 3306 where the MySQL server is running.
If you want a client on a different machine to connect to this server, you must use the real hostname of the server in the JDBC URL. Of course you must allow access from this client to the server.
Edit: If you must use a relational database but can not access a server, you should use an embedded database. A widely used is H2.
I have an oracle12c database setup on my windows 8 machine & I am trying to access this database through JDBC from ubuntu(Linux) machine present in local area network.
When am trying to establish connection through JDBC, getting the following exception
The network adapter could not establish connection.
I have ensured the following.
1. Disabled the firewalls between both the machines.
2. the URL is proper & I tired using both hostname as well as ip address.
3. listener is up and running on port 1521.(lsnrctl stat shows the listener is READY)
I have done extensive google search about this. Please help.
Thanks in advance. Please let me know if you need more details.
make sure you have used proper jdbc driver for that database connection.
try to telnet the computer (Windows 8) that is running DB from client computer (Ubuntu).
I am attempting to create a MySQL and Java client app for my home network.On the server machine I successfully connected to the MySQL as root
Now I want to connect to MySQL from my client PC using the Java client program,
How to do this??
Do i need to install Tomcat Server to run on server for this.
I am using Windows 7 on all my clients and server machines.
Tomcat server is used for web applications.You just need to create a JDBC code and in the URL string just give the ip address of the system where mysql is installed.For example
connection = DriverManager
.getConnection("jdbc:mysql://192.168.1.205:3306/database_name","root", "password");
Also if you have not granted the permission in mysql then grant it .See this for granting permission for access to mysql on remote system
Depending on what you want to achieve, you need to establish a JDBC connection to the server. Take a look at the JDBC trail for more details.
This will allow you to connect directly from you client machine to your database server. This would be done using the required JDBC connection URL for the MySQL connection, for example jdbc:mysql://[host][,failoverhost...][:port]/[database] ยป
[?propertyName1][=propertyValue1][&propertyName2][=propertyValue2]..., check out Driver/Datasource Class Names, URL Syntax and Configuration Properties for Connector/J for more details.
You may also need to configure your MySQL server to allow remote access before you can connect
You just need to do two things:
Make sure the server hosting MySQL allows incoming connections
Write JDBC code and use your MySQL server hostname/ipaddress in the jdbc string to connect and use it.
I am attempting to create a MySQL DB and Java client app for my home network. I haven't really had any experience with MySQL other than PHPMyAdmin for a website backend (also have used SQLite). I have downloaded the full MySQL installation and a test DB from the MySQL website. On the server machine I successfully connected to the DB as root. Not a difficult task.
Now I want to connect to the DB from my client PC, just to check I can. Eventually I will use the JDBC driver to connect from my Java client app, but before that I just want to check I can connect.
How should I do this? SHould I just install the MySQL command line program onto the client PC?
EXTRA INFO: forgot to add, I'm using Windows 7 on all my machines.
Yes, you could install the MySQL to get MySQL command line program and connect with it, but also you can use another MySQL client tool like PHPMyAdmin, dbForge Studio for MySQL or another one.
To connect from remote host you should create special accout for it, e.g. - 'user_name'#'your_host_name'. Find more information here -
Specifying Account Names
Account Names and Passwords