Connecting to remote mysql server using jdbc.

Connecting to remote mysql server using jdbc.

How to Connect to remote mysql server using jdbc.

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
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
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...({}); net.sourceforge.jtds.jdbc.Driver jdbc:jtds:sqlserver
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
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
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
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
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
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
jsp fie execution in tomcat and using mysql - JDBC
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... The username and password that we used in the JDBC Connection
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
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
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  
Connecting to the Database Using JDBC and Pure Java driver
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
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
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-connector
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
Connecting different Servers - Java Server Faces Questions
Connecting different Servers  How can i connect two different tomcat server in an application
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
jdbc driver for mysql - Java Beginners
jdbc driver for mysql  I need jdbc driver program for connecting java progrma to mysql. Please any one send me the url to download the driver... of jdbc-mysql database connectivity and idea about jdbc and mysql driver
MYSQL Java Connector Library
Connector Library for using MYSQL server in your application. MYSQL Java... for MySQL required for connecting Java and MYSQL Database Server. You can download... This article discuss 'how to connect Java and MYSQL using MYSQL connector'
Prepared statement JDBC MYSQL
Prepared statement JDBC MYSQL  How to create a prepared statement in JDBC using MYSQL? Actually, I am looking for an example of prepared statement.   Selecting records using prepared statement in JDBC
How to download MySQL JDBC driver?
How to download MySQL JDBC driver?  Hi, What is JDBC Driver? How to download MySQL JDBC driver? Thanks   Hi, JDBC - Java database... program. To connect to MySQL database from Java program we need JDBC Driver of MySQL
Connecting to MySQL database and retrieving and displaying data in JSP page
Connecting to MySQL database and retrieving and displaying data in JSP page... web application. Creating Table in the database.ADS_TO_REPLACE_1 Using a JDBC...; try{ String url="jdbc:mysql://192.168.10.2/tutorial?user
how to send emails to many using jsp by connecting to ms access dabase.
how to send emails to many using jsp by connecting to ms access dabase.  Hi. I am trying to send multiple emails and the email ids are stored in a table in a msaccess database.I am using jsp for this.And finally there should
Mysql & java - JDBC
to connect to mysql 5.1 using java. But it shows error about: Class.forName...; String url = "jdbc:mysql://localhost:3306/"; String dbName... on JDBC visit to : http://www.roseindia.net/jdbc/jdbc-mysql/MysqlConnect.shtml
how to connect mysql with JDBC - JDBC
in the database MYsql, i have to connect them now using JDBC, can u please suggest me...(); } } Thanks Rajanikant  Hi friend, To mysql connect using JDBC... { connection = DriverManager.getConnection("jdbc:mysql://localhost
using Blob in jdbc - JDBC
using Blob in jdbc  Hi, I got an Exception when i was trying to insert one image into oracle 10g database the exception is Exception in thread..."); Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost
How to Retrieve Excel data into mysql using type 2 JDBC-ODBC driver
How to Retrieve Excel data into mysql using type 2 JDBC-ODBC driver  Can any please help it is very urgent. I tried to read excel sheet using ODBC... using ODBC.plz help me guys..........   Follow these steps: Open Data
mysql installation problem - JDBC
mysql installation problem  Hi, when i installing mysql server on my pc in MySQL Server Instance Configuration Wizard,I enter the root pw.... Access denied for user 'root'@'localhost' (using password:NO) Please tell me
database connectivity using mysql
seconds) I am using Netbeans 5.5, mysql server 5.0, to get data from table...[]) throws SQLException { try { String connectionURL = "jdbc:mysql...database connectivity using mysql  java file: eg1.java package eg
jdbc connectivity to mysql tutorial
jdbc connectivity to mysql tutorial  here is complete jdbc connectivity to mysql tutorial for newbies. Person who don't even know how to install mysql and don't know about which driver to use can do with ease
maven mysql jdbc driver
maven mysql jdbc driver  How to add the maven mysql jdbc driver dependency in the pom.xml file of a maven based application?   Hi, Its...;groupId>mysql</groupId> <artifactId>mysql-connector-java<
JDBC: Create Table Example
JDBC: Create Table Example In this section, we are going to create table using JDBC and using database MySql. Create Table : Database table is collection... connection URL has the following format: jdbc:mysql://[host][:port]/[database
connecting databases
connecting databases  I need to connect mysql on 2 or more remote pc'c. how can i giv the ip address for 2 or more systems. is it possible to connect to the required systems by user specifying the database and table name my
jsp using include & with mysql
jsp using include & with mysql  Sir, I am creating a login application using jsp & Mysql. The Codes are--- Html File...... <...; <param-value>jdbc:mysql://localhost:3306/userinfo</param-value> <
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
Null pointer exceptation-Java Servlet web application,Problem connecting with MYSQL database
="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/database_name?autoReconnect...="password" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost...Null pointer exceptation-Java Servlet web application,Problem connecting
multiple JComboBoxes using with JDBC
=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root"...multiple JComboBoxes using with JDBC  how to use JComboBoxes with JDBC in java  Hi Friend,Try the following code:import java.awt.*;import
JAVA & MYSQL - JDBC
JAVA & MYSQL  How can we take backup of MySQL 5.0 database by using...;Hi Friend, Please visit the following page for working example of MySQL backup. This may help you in solving your problem. www.roseindia.net/mysql/mysql
mysql problem - JDBC
= "jdbc:mysql://localhost:3306/test"; Connection con=null; try...mysql problem  hai friends please tell me how to store the videos in mysql plese help me as soon as possible thanks in advance   
upgrade mysql cpanel server
upgrade mysql cpanel server  upgrade mysql cpanel server
JDBC using Spring framework - JDBC
JDBC using Spring framework  Hi, I am using Spring framework in my project. I am making a call to the DB2 procedure using datasource and it returns... the code i'm using... HashMap params = new HashMap(); params.put("Username
mysql tables - JDBC
"); con = DriverManager.getConnection("jdbc:mysql://localhost:3306/databasename...mysql tables  hi, I have a table in MySql, having fields, emp_id,emp_name,emp_vertical,emp_supervisor. i need a JDBC program with driver

Ads