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



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

Have Programming Question? Ask it here!
 
 
 


Java Coder
Connecting to remote mysql server using jdbc.
1 Answer(s)      2 years and 3 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
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
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
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
Connecting different Servers - Java Server Faces Questions
Connecting different Servers  How can i connect two different tomcat server in an application
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
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
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  
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
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
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
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. Using a JDBC driver...; Statement stmt=null; try{ String url="jdbc:mysql
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'
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
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
upgrade mysql cpanel server
upgrade mysql cpanel server  upgrade mysql cpanel server
could not connect to the server - JDBC
to the remote MySqL server, i got an exception like...) at java.lang.Thread.run(Unknown Source) ** END NESTED EXCEPTION ** Last packet sent to the server...;Hi friend, Read for more information. http://www.roseindia.net/jdbc
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
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
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 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 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
Connecting to a database through the Proxy.
Connecting to a database through the Proxy.  Connecting to a database through the Proxy I want to connect to remote database using a program that is running in the local network behind the proxy. Is that possible
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
jdbc odbc sql server exception
jdbc odbc sql server exception  Hi, I am trying to use sql server with java jdbc odbc but I am getting this exception java.sql.SQLException: [Microsoft][SQL Server Native Client 10.0][SQL Server]Incorrect syntax near '@P1
Server DB connection - JDBC
Server DB connection  Hello Guys I want to connect two databases.... One database is on my localhost and the other one is on server, I want to transfer the data from my localhost database to the database on the server. I have
mysql server connectivity - Java Server Faces Questions
mysql server connectivity  hello friends, my question... friend, http://www.roseindia.net/jdbc/index.shtml http://www.roseindia.net/mysql/ Thanks
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<
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
Advertisements
 

 

 

DMCA.com