Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JDBC Connecting to remote mysql server using jdbc.
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Java Coder
Connecting to remote mysql server using jdbc.
1 Answer(s)      2 years and 5 months ago
Posted in : JDBC


How to Connect to remote mysql server using jdbc.


Advertisement
View Answers

May 11, 2012 at 11:08 AM


First configure your MySQL server to accept remote connections by enabling external connection for MySQL server. Use the IP / hostname of the remote machine in your database connection string, instead of localhost.

Example :

package roseindia.net;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class RemoteMYSQLServer {
        public static void main(String[] args) throws SQLException {
                Connection con = null
                Statement stmt = null; 
                ResultSet rs = null;

                String conUrl = "jdbc:mysql:// 192.168.10.25:3306/";
                String driverName = "com.mysql.jdbc.Driver";
                String databaseName = "student";
                String usrName = "root";
                String usrPass = "root";
                try {
                        // Loading Driver
                        Class.forName(driverName). newInstance();
                } catch (ClassNotFoundException e) {
                        System.out.println(e.toString());
                }
                try {
                        // Getting Connection
                        con = DriverManager.getConnection(conUrl + databaseName, usrName,
                                        usrPass);
                        stmt = con.createStatement();

                        String query = "SELECT * FROM  student'";

                       rs= stmt.executeUpdate(query);
                   if (rs.next()) {
                System.out.println(rs.getString(1));
            }

                } catch (Exception e) {
                        System.out.println(e.toString());
                } finally {
                        // Closing Connection
                        con.close();
                        stmt.close();
                }
        }
}


Related Tutorials/Questions & Answers:
Connecting to remote mysql server using jdbc.
Connecting to remote mysql server using jdbc.  How to Connect to remote mysql server using jdbc
Connecting to the Database Using JDBC and Pure Java driver
Connecting to the Database JDBC Driver In our search engine we are using MySQL database server and MM.MySQL Driver... this driver to make connections to MySQL server from both Java
Advertisements
Encountering error when connecting MSSQL Server 2005 using Hibernate 3.0
Encountering error when connecting MSSQL Server 2005 using Hibernate 3.0 ... the following error when connecting to the MSSQLServer 2005 using hibernate 3.0 My hibernate.cfg.xml is as under net.sourceforge.jtds.jdbc.Driver jdbc
Connecting to MYSQL Database in Java
Connecting to MYSQL Database in Java  I've tried executing the code... = "jdbc:mysql://localhost/"; String dbName = "textbook"; String driver... the following link: JDBC MySQl Connectivity   I have mysql-connector
can't connect to MySQL Server(10060) - JDBC
created a DB in the Hosting MySQL server and now i want to create a table By using MySQL front end. Can we connect to the MySQL server using the I.P address...can't connect to MySQL Server(10060)  Hii Sir, I am working
not able to connect to mysql using.. jdbc
not able to connect to mysql using.. jdbc   i am not able to connect to mysql using jdbc .. is there any classpath that i need to set..because i am using mysql-connector-java jar file..to connect to mysql.. Pls provide the steps
using pb datawindow activex with jdbc for mysql - JDBC
using pb datawindow activex with jdbc for mysql  Hi, I am trying to use datawindow activex in a web page. I need to connect to mysql database located on the server. I have downloaded the connectj for mysql. What should
ssh to remote server - JavaMail
ssh to remote server  I designed an application for feedback, in that application i want to write a code for automatic mail sending, can you please tell me how to write code for that. Please help us
Connecting JTable to database - JDBC
Connecting JTable to database  Hi.. I am doing a project on Project Management System for which i created the user interfaces.. I have a user...("jdbc:odbc:access"); for(int i=0;i  Hi Friend, Make one change
java jdbc connecting probelm - JDBC
java jdbc connecting probelm  import javax.servlet.*; import javax.servlet.http.*; import javax.sql.*; import java.io.*; public class ECom...=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","scott","tiger
Error in connecting to the mySQL database in TOMCAT using more than one PC (database connection pooling)
Error in connecting to the mySQL database in TOMCAT using more than one PC...="com.mysql.jdbc.Driver" url="jdbc:mysql://10.9.58.8:3306/alcs_htht"/> </Context>...-INF/web.xml</WatchedResource> <Resource name="jdbc/HTHLogDB" auth
doubt in connecting mysql in flex - XML
doubt in connecting mysql in flex  The ?Create application from... clicks;Here is an example whichusephp as back-end and MySql as DataSource:First...; Than create a project that use PHP as server technology:Right Click
doubt in connecting to mysql in flex - XML
doubt in connecting to mysql in flex  The ?Create application from... clicks;Here is an example whichusephp as back-end and MySql as DataSource:First... = innodb; Than create a project that use PHP as server technology:Right Click
connecting jsp to mysql - JSP-Servlet
connecting jsp to mysql  Hi, i am working on 'Web application development' project that uses JSP, MySQL and tomcat.i am not able to connect to the mysql database through jsp. After downloading the mysql-connector-java-5.0  
java connecting to oracle db - JDBC
java connecting to oracle db  how to connect oracle data base... oracle.jdbc.driver.*; import oracle.sql.*; 2) Load and Register the JDBC driver...) Connect to database:*********** a) If you are using oracle oci driver,you have
spring mvc configuration with mysql using jdbc
spring mvc configuration with mysql using jdbc  hai I want to configure web mvc with mysql using jdbc template. when I submit values using registration form it will reflect on database which i was created earlier. send me code
Tomcat Server configuration with Eclipse at remote machine
Tomcat Server configuration with Eclipse at remote machine  "Several... may be using the port. To start this server you will need to stop the other... same web application on remote machine by different users using different
Connecting different Servers - Java Server Faces Questions
Connecting different Servers  How can i connect two different tomcat server in an application
How to send URL in Post request from local server to remote server?
How to send URL in Post request from local server to remote server?  ... server(using Tomcat). Now i want: 1> How to establish a Connection... containing- "https://IPAddress:Port/contextpath/parameters" to remote server
jsp fie execution in tomcat and using mysql - JDBC
that we used in the JDBC Connection are the MySql username and password.The...jsp fie execution in tomcat and using mysql  I created 2 jsp files... and password to enter into the Mysql database account.the other named
Connecting to MySQL
(); bds.setDriverClassName("com.mysql.jdbc.Driver"); bds.setUrl("jdbc:mysql...-dbcp.jar, commons-pool.jar, j2ee.jar and mysql-connector-java-5.1.7-bin.jar...-collections.jar;lib/commons-dbcp.jar;lib/commons-pool.jar;lib/j2ee.jar;lib/mysql
unable to retrive the data from mysql using servlet using jdbc driver
unable to retrive the data from mysql using servlet using jdbc driver  Hi, i have a servlet program..to verify the login and redirect to correct... Connection con = null; String url = "jdbc:mysql://localhost:3306
remote procedure call using java - JSP-Servlet
remote procedure call using java  what is the romote procedure call and related coding in java?  Hi Friend, The RPC (Remote Procedure... to be communicated to a remote server. JAX-RPC makes it easier for applications or Web
connecting to ssh using ir00co and postgres - Struts
connecting to ssh using ir00co and postgres  how can i connect to this servers after i succesfully login in the ldap?will i open new connection?any advice will be appreciated... ebok
Remote file transfer in java using SSH & Telnet
Remote file transfer in java using SSH & Telnet  How to upload & download a file in java using SSH & Telnet
mysql jdbc connectivity
mysql jdbc connectivity  i want to connect retrieve data from mysql using jdbc
jsp -sevlet connecting to database using dropdown
jsp -sevlet connecting to database using dropdown  How can I get my dropdown list from oracle database and then submit it to another table in JSP. I am thinking of a form that links to a servlet and the servlet connects
MySQL Driver for JDBC - JDBC
MySQL Driver for JDBC  Sir, I have started reading your JDBC tutorial for MySQL. I have installed MySQL successfully. But I do not have MySQL... Example."); Connection conn = null; String url = "jdbc:mysql://localhost:3306  
jdbc mysql - JDBC
=DriverManager.getConnection("jdbc:mysql://localhost:3306/ram","root","root...jdbc mysql  import java.sql.*; public class AllTableName... sent to the server was 31 ms ago. at com.mysql.jdbc.Connection.createNewIO
Getting message from the server using RPC( Remote Procedure Call )
Getting message from the server using RPC( Remote Procedure Call... describes the procedure of retrieving message from the server via RPC. The steps involved in geting message from the server are described below:- Step1:-Right
Advertisements
 

 

 

DMCA.com