I'm currently working on a project for conducting online test for our college,
I have successfully performed the test using our internal servers, now I need to host online through private hosting services, everything is ready except for the Database.
The database is created using the same service provider but I don't know how to modify the command line for remote hosting.
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/placement","username","password");
This is the command line I used in our internal server, now how to modify it for remote SQL database
The remote db name is "epiz_22735410_placement_db"
The host name is "sql104.epizy.com"
You could follow this pattern:
String url = "jdbc:mysql://HOST:PORT/DATABASE";
Connection con = DriverManager.getConnection(url, "username", "password");
Instead of localhost use sql104.epizy.com everything else should stay the same if it's working on local (assuming your credentials etc are the same as local)
e.g.
mysql://sql104.epizy.com:3306/epiz_22735410_placement_db","username","password");
Related
I am trying to create a Java application that connects to a MySQL database and I am using AWS to host it. So I created the AWS RDS instance and I got it to connect to the MySQL workbench just fine. My problem arises when I am trying to use JDBC to connect to it.
I have security groups that allow traffic from anywhere, but I also tried just allowing my IP.
I had it working when I was using a localhost but now I'm trying to move it to a server so keeping it localhost isn't an option (used localhost to test the application and such)
I made sure that my user was a remote user by doing
SELECT * from mysql.user;
And made sure that the host was a '%' and that it had all the privileges
So my code I'm trying to connect with in Java is
String connectionURL = "jdbc:mysql:/{hostname}:{port}/{database name}/?autoReconnect=true&useSSL=false";
String username = "username";
String password = "password";
con = DriverManager.getConnection(connectionURL, username, password);
Of course I have the actual host, port, and such in there just changed it for posting online.
When I try running it on Eclipse it says this java.lang.Exception: Database not found
I looked up some tutorials on AWS docs to make sure it lined up, which it all did.
Anyone have any idea why it might be connecting to MySQL workbench and not the JDBC?
I have build an application in java, application is one and will be used on 3 different systems,And therefore the database of that application must be online to keep all 3 applications with up to date database...
In starting I developed my application based on localhost (wampserver) and used database in "PhpMyAdmin", and hopefully application is fully developed and ready to run.. but the problem is online database connectivity!
I have uploaded my database on a Site in PhpMyAdmin and they provided below information:
and the for connecting my app to this DB is:
String url = "jdbc:mysql://fdb12.biz.nf:3306/";
String dbName = "1738412_wstore";
String driver = "com.mysql.jdbc.Driver";
String userName = "1738412_wstore";
String password = "Password";
Class.forName(driver).newInstance();
Connection conn = DriverManager.getConnection(url+dbName,userName,password);
now when I run my application it shows below error:
I dont know what the problem is there, please help me out through this..
I faced the same issue and the following helped me to solve.
http://support.hostgator.com/articles/cpanel/how-to-connect-to-the-mysql-database-remotely
Hopefully, your hosting provider should have same type of cpanel to configure MySQL database for remote connections.
Check for firewall.
Check if mysql is running.
2 things you can try:
Install MySql client locally on your machine and connect like: mysql -h fdb12.biz.nf -u 1738412_wstore -P<password>
This should work before you try anything else.
Make sure you're using the right imports in your code. See [here][1].
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
I think your DB server doesn't allow remote connections.
Try hosting in:
http://www.freesqldatabase.com/freemysqldatabase/
It's free and allow remote DB connections.
Good Luck!!!
Considering the Biz.nf FAQ:
How can I connect to my MySQL/PostgreSQL database? What settings
should I use for my script/software?
MySQL/PosgreSQL database connection can be established with script/software hosted only on your
web hosting account (meaning no remote access is allowed due to
security reasons). The following settings are needed:
So, since biz.nf does not allow remote access, it will be difficult for you to interact with their MYSQL server for your application.
The best solution and the most simple is probably to find a new provider which will allow the remote access. Heroku.com works very well.
If you really want to use the biz.nf services, it will be more difficult.
It's not a script or credential problem.
Maybe you can (probably not), try to login by SSH to configure your server to enable remote access to your MYSQL database server.
From the free plan, you will not have any access to the online SSH tool and you will need to configure your domain for a SSH connection.
In SSH, and it probably will not work considering the FAQ, you could try to simply modify your /etc/mysql/my.cnf file by commenting the bind-address line wich by default only allows local access (127.0.0.1). Then, try to restart your MYSQL service with: a simple service mysql restart to verify if the remote connection works.
If the remote connection still doesn't work after this, the only way I can find for the moment (unless you completely change your hosting provider) would be to create a kind of API hosted directly on the server and your Java program could interacts with your services (In JSON, by example).
I'm writing a program to push stuff into a remote database. My database is stored on a redhat server, while my program is written on a windows machine.
I dont want to give out my server addresses but lets say my Linux server is xx.xx.xx.xx8
MySQL Workbench in windows says that my mysql server host is 127.0.0.1:3306
I know there are a million similar questions but each one is pretty unique to the situation.
I've been using http://www.vogella.com/tutorials/MySQLJava/article.html#javaconnection as a guide but this looks like a local connection.
I have also been referencing this but it confuses me.
Here's a mock up of some code i think may work:
Connection connection = null;
String dburl = "jdbc:mysql://127.0.0.1:3306/Db_Name";
String userName = "user";
String passWord = "password";
try {
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection(dburl, userName, passWord);
Statement st = connection.createStatement();
String query = "INSERT INTO Example (`TestColumn`) VALUES('hello')";
int rsI = st.executeUpdate(query);
System.out.println("Hi");
}catch (Exception e) {
System.out.println(e);
} finally {
if (connection != null) {
try {
connection.close();
System.out.println("Database connection terminated");
} catch (Exception e) { /* ignore close errors */ }
}
}
that is based on the link i provided. All i changed was the address. I have no idea where the server address xx.xx.xx.xx8 should go.
In order to connect to the remote database you need to know the external ( or called public ) ip address of the server.
String dburl = "jdbc:mysql://85.65.85.222:3306/Db_Name"
Even if your database on server says it listens on localhost:3306, you can still connect to it using public ip with correct port. (providing you have sufficient access rights to the server)
Sometimes there may be situation that even if you know the remote server IP address you still won't be able to connect to remote database directly perhaps due to blocked port or other ACL issues ( and this is ofc applicable if you have no control over this). You could however create ssh tunnel to that server and create a port forward.
JSch jsch = new JSch();
Session session = jsch.getSession(user, host);
session.setPassword(password);
session.connect(timeout);
session.setPortForwardingL(listenPort, destHost, destPort);
example ssh connnection could look something like this:
ssh user#85.65.85.222 -Llocalhost:5050:127.0.0.1:3306 <- this will create a ssh tunnel with port forwarding, meaning on your local machine where you have your code and whole environment you will still be able to connect to remote database using
String dburl = "jdbc:mysql://localhost:5050/dbname"
Just to clarify for anyone looking at this later...
localhost is always the machine you are sitting at - always. There is no way you will ever connect to a remote box using localhost. Also, the IP address 127.0.0.1 is equivalent to localhost, so don't use that either.
You may see that the database binds to localhost or 127.0.0.1 on the database server. That is ok. Use the IP address of the server running the database in your database connection URL
mysql:jdbc://<IPOfServer>:<PortOfServer>/<DbName>).
You can find the IP address of the server by running the following command on the database server...
Windows: ipconfig
Linux: ifconfig
Good luck!
You can see what documentation says:
The method DriverManager.getConnection establishes a database
connection. This method requires a database URL, which varies
depending on your DBMS. The following are some examples of database
URLs:
MySQL: jdbc:mysql://localhost:3306/, where localhost is the name of
the server hosting your database, and 3306 is the port number
So, for MySQL Connector/J Database URL
The following is the database connection URL syntax for MySQL Connector/J:
jdbc:mysql://[host][,failoverhost...]
[:port]/[database]
[?propertyName1][=propertyValue1]
[&propertyName2][=propertyValue2]...
Where:
host:port is the host name and port number of the computer hosting your database. If not specified, the default values of host and port are 127.0.0.1 and 3306, respectively. So, every operation you do will be applied on this post
database is the name of the database to connect to. If not specified, a connection is made with no default database.
failover is the name of a standby database (MySQL Connector/J supports failover).
propertyName=propertyValue represents an optional, ampersand-separated list of properties. These attributes enable you to instruct MySQL Connector/J to perform various tasks.
Update: if you have a remote databases (your remote server) that you want to access to, you should have for example:
String dburl = "jdbc:mysql://<REMOTE_HOST>:3306/Db_Name"; //replace with your remote host
... // here all the code related to your remote host
Note: if you remote server has in its configuration "localhost" you have to figure out its public ip address by executing ifconfig. Then use its ip address on your string. As important note your remote server must be configured to allow remote connections.
if you connect to a server (ie. with the ip xx.xx.xx.xx8) you specify through the port (which is usually 3306) that you want to connect to the databaseserver on that machine. so simply use:
String dburl = "jdbc:mysql://xx.xx.xx.xx8:3306/Db_Name";
as your connectionstring.
If you dont know the port, mysql is running, have a look in your /etc/mysql/my.cnf file. There should be the port specified.
Also have a look at your firewallrules if you can't connect and make sure you enabled remoteconnections (here is a good tutorial to enable it: http://www.cyberciti.biz/tips/how-do-i-enable-remote-access-to-mysql-database-server.html).
I have encountered a problem when setting up a Data Source in Oracle WebLogic Server that is an AS400. When setting it up and testing the connection I get the error message:
"The application requester cannot establish the connection"
When checking on IBMs website I found the following:
What does "The application requester cannot establish the connection"
mean?
The Toolbox JDBC driver uses the system name, user ID, and password
provided in the call to DriverManager.getConnection() to establish a
connection to the IBM i database. If any of these are not provided,
the Toolbox JDBC driver will display a sign-on prompt. If the Toolbox
JDBC driver can not sign on to the system for any reason, it will
throw an SQLException with the message "The application requester
cannot establish the connection". Here is a list of potential causes
for this exception: The system name is incorrect. One way to verify
this is to use ping with the specified system name. If ping fails,
then there is a TCP/IP configuration problem between your client and
the system. The user ID or password is incorrect. The IBM i database
host server is not started. You can start this by running STRHOSTSVR
*DATABASE on the IBM i command line. You can verify if the IBM i database host server is running
using the utilities.JPing application.
(http://www-03.ibm.com/systems/power/software/i/toolbox/faq/jdbc.html#faqC6)
When I ping the server, it fails - which also makes sense. However, when I use just a plain java file that opens a connection, fires an sql and closes the connection like
connection1 = DriverManager.getConnection("server", "user", "password")
Statement statement1 = connection1.createStatement();
ResultSet result1 = statement1.executeQuery("SQLquery")
i get a perfect connection and correct result. How is this possible? How can I connect via WebLogic and ODI?
PS: I already installed the AS400 driver according to this manual
all of the examples, unfortunately on the net are consumed of downloading a MySQL database to your computer rather than taking advantage of Online Database.
What should I replace the following code to get data from an online db rather than a 3306 typical desktop MySQL;
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/DBNAME", "usrname", "pswd") ;
Since not too much information was given, we will use an example - let's say the database is located at user3129325.com, and is hosted by a web hosting provider that allows remote SQL. If you wanted to connect to the database named "DBNAME" (using the same name as in your example), you would want to use the following command:
Connection conn = DriverManager.getConnection("jdbc:mysql://user3129325.com:3306/DBNAME", "usrname", "pswd") ;
Just simply replace localhost with the URL of the remote MySQL database.