Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how To connect the mysql database from java with my webserver

 
Satchidananda Mohanty
Ranch Hand
Posts: 78
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Jan Cumps
Bartender
Posts: 2588
11
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Satchidananda Mohanty
Ranch Hand
Posts: 78
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
BTW, what is the error ?
Are you sure the Database is up ? are you able to ping to the IP ?
 
Satchidananda Mohanty
Ranch Hand
Posts: 78
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2588
11
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 78
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jan.
I am trying.
 
Satchidananda Mohanty
Ranch Hand
Posts: 78
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2588
11
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good that it works.
Is your webserver (application server) also hosted at secureserver.net ?
 
Balu Sadhasivam
Ranch Hand
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic