File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes how To connect the mysql database from java with my webserver Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "how To connect the mysql database from java with my webserver" Watch "how To connect the mysql database from java with my webserver" New topic
Author

how To connect the mysql database from java with my webserver

Satchidananda Mohanty
Ranch Hand

Joined: Mar 12, 2008
Posts: 77

hi there ,

Can you help me regarding this..?

I am using this in local system
conn =DriverManager.getConnection ("jdbc:mysql://localhost/dbname","userid", "password");
conn =DriverManager.getConnection ("jdbc:mysql://127.0.0.1:3306/dbname","userid", "password");

both are working properly.

But when I am trying to connect with server with this


conn =DriverManager.getConnection ("jdbc:mysql://10.6.145.9/dbname","userid", "password");
conn =DriverManager.getConnection ("jdbc:mysql://10.6.145.9:3306/dbname","userid", "password");

it is not working..

So how can I connect to my database server.Can anybody post the solution ??


Thanks in advance

zeet


Zeet

SCJP 6.0
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2503
    
    8

Can you connect from the same computer to the same database using the MySQL tools?

it is not working..
What does it say? Please post the error.


OCUP UML fundamental and ITIL foundation
youtube channel
Satchidananda Mohanty
Ranch Hand

Joined: Mar 12, 2008
Posts: 77

Hi jan
Thanks.

Yeah I am able to connect my local database with the same.
But while I am trying to connect on my webserver database on godaddy.com that is not able to connect.
And that is not showing any error,exception.

This is the piece of the code.
import java.io.*;
import java.util.*;
import javax.sql.*;
import java.sql.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.io.IOException;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.*;
import java.sql.Statement;


public class test extends HttpServlet {

protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out=response.getWriter();

Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();//out.println("test");

/* it is working fine
conn =DriverManager.getConnection ("jdbc:mysql://127.0.0.1:3306/databasename","userid", "password");
*/

//conn =DriverManager.getConnection ("jdbc:mysql://10.195.1.6:3306/databasename","userid", "password");

conn =DriverManager.getConnection ("jdbc:mysql://p3smysqladmin01.secureserver.net/databasename","userid", "password");
out.println("Connected to the database");

} catch (Exception e) {
e.printStackTrace();
}


}

}

thanks .
zeet
Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874

BTW, what is the error ?
Are you sure the Database is up ? are you able to ping to the IP ?
Satchidananda Mohanty
Ranch Hand

Joined: Mar 12, 2008
Posts: 77

Thanks Balu,

Yeah I tried that .But I am not able to ping that server.
It is showing Requested time out.

But on browser I am able to login that server with my userid and password.
So I am not able to track the error.

While I am executing the servlet it is showing the blank page.

Thanks..
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2503
    
    8

Seems to be an administration server, not the database server.
Contact secureserver.net , and ask them if it is possible to do what you are trying to do.

Regards, Jan
Satchidananda Mohanty
Ranch Hand

Joined: Mar 12, 2008
Posts: 77

Thanks Jan.
I am trying.
Satchidananda Mohanty
Ranch Hand

Joined: Mar 12, 2008
Posts: 77

Now it is working. and I am able to connect my database.

The problem is that I was trying to connect my database server from my local development system.
Thats why it was not able to connect due to the firewall issues in server.
But I have created a new jsp page with connection scriptlets and run that in my webserver.
So Now that is working fine and able to connect the database.

thanks,

zeet
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2503
    
    8

Good that it works.
Is your webserver (application server) also hosted at secureserver.net ?
Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874

satchidananda mohanty wrote:Now it is working. and I am able to connect my database.

The problem is that I was trying to connect my database server from my local development system.
Thats why it was not able to connect due to the firewall issues in server.
But I have created a new jsp page with connection scriptlets and run that in my webserver.
So Now that is working fine and able to connect the database.

thanks,

zeet


Thats what with most of the service providers. if your machine able to connect to hosted database, thats security violation.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how To connect the mysql database from java with my webserver