Go4Expert

Go4Expert (http://www.go4expert.com/)
-   MySQL (http://www.go4expert.com/forums/mysql-forum/)
-   -   unable to connect to the database on webserver (http://www.go4expert.com/forums/unable-connect-database-webserver-t16677/)

painamrata 26Mar2009 15:04

unable to connect to the database on webserver
 
:cryin:i have designed a website in jsp...my problem is i am able tocnnect to the database through local host(tomcat) but when i hosted the website its unable to connect..i just cant figure it out..i will copy paste the code below.plase some one helpmeout..
Code:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 >
<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>
<style type="text/css">
<!--
.style47 {font-size: x-large; font-family: Verdana, Arial, Helvetica, sans-serif; color: #346FAC;}
-->
</style>
<body bgcolor="#FFFFFF">
<form method="get" action="enq_thanks_pg.jsp">
<p>
<%
String subject = request.getParameter("subject");
String enquirydetails = request.getParameter("enquirydetails");
String firstname = request.getParameter("firstname");
String lastname = request.getParameter("lastname");
String companyname = request.getParameter("companyname");
String companyaddress = request.getParameter("companyaddress");
String zipcode = request.getParameter("zipcode");
String phoneno = request.getParameter("phoneno");
String emailadd = request.getParameter("emailadd");
/* Create string of connection url within specified
format with machine name,
port number and database name. Here machine name id
localhost and database name is student. */
String connectionURL = "jdbc:mysql://IPaddress:3306/student";
// declare a connection by using Connection interface
Connection connection = null;
PreparedStatement pstatement = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
int updateQuery = 0;
 
// check if the text box is empty
if(subject!=null && enquirydetails!=null && firstname!=null && lastname!=null && companyname!=null && companyaddress!=null && zipcode!=null && phoneno!=null && emailadd!=null)
{
// check if the text box having only blank spaces
if(subject!="" && enquirydetails!="" && firstname!="" && lastname!="" && companyname!="" && companyaddress!="" && zipcode!="" && phoneno!="" && emailadd!="")
{
try {
/* Create a connection by using getConnection()
method that takes parameters of string type
connection url, user name and password to connect
to database. */
connection = DriverManager.getConnection
(connectionURL, "root", "XXXX");
// sql query to insert values in the secified table.
String queryString = "INSERT INTO enquiry(subject,enquirydetails,firstname,lastname,companyname,companyaddress,zipcode,phoneno,emailadd) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
/* createStatement() is used for create statement
object that is used for
sending sql statements to the specified database. */
pstatement = connection.prepareStatement(queryString);
pstatement.setString(1, subject);
pstatement.setString(2, enquirydetails);
pstatement.setString(3, firstname);
pstatement.setString(4, lastname);
pstatement.setString(5, companyname);
pstatement.setString(6, companyaddress);
pstatement.setString(7, zipcode);
pstatement.setString(8, phoneno);
pstatement.setString(9, emailadd);
updateQuery = pstatement.executeUpdate();
if (updateQuery != 0) { %>
</p>
<p></p>
 
<%
String ssub = request.getParameter("subject");
 
String senq = request.getParameter("enquirydetails");
 
String sfname =request.getParameter("firstname");
 
String slname = request.getParameter("lastname");
 
String scname = request.getParameter("companyname");
 
String scadd = request.getParameter("companyaddress");
 
String szipcode = request.getParameter("zipcode");
String sphone = request.getParameter("phoneno");
 
String semail = request.getParameter("emailadd");
%>
 
<table width="633" height="32" border="0" cellpadding="0" cellspacing="1" align="center">
<tr>
<td width="257" align="center"><img src="images/dcg-final-logo.gif" alt="logo" width="149" height="67" /></td>
<td width="699"><span class="style47">Direct Consulting Group</span></td>
</tr>
</table>
<p>&nbsp;</p>
<form method="post" action="test_mid.jsp">
<center>
<table width="368" border="0" align="center">
<tr>
<td width="40%" align="left">Subject : <font color="#000000"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<%=ssub%> <br>
<br></b></font>
Enquiry Details : <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<%=senq%><br><br></b>
Firstname : <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<%=sfname%><br><br></b>
 
Lastname : <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<%=slname%><br><br></b>
 
Company Name : <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<%=scname%><br><br></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bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="enq_thanks_pg.jsp"> CLICK HERE TO CONTINUE</a></p>
 
<%
}
}
catch (Exception ex) {
out.println("sorry your data couldnot be processed due to system error,please try again...");
 
}
finally {
// close all the connections.
pstatement.close();
connection.close();
}
}
}
%>
</form>
</form></body>


coderzone 26Mar2009 15:55

Re: unable to connect to the database on webserver
 
Quote:

connection = DriverManager.getConnection
(connectionURL, "root", "XXXX");
are you sure the username/password on your server is correct?

painamrata 26Mar2009 16:14

Re: unable to connect to the database on webserver
 
yes it is...i checked it agian..

painamrata 26Mar2009 16:20

Re: unable to connect to the database on webserver
 
we should put the user name and password of the mysql server right..m using putty..

coderzone 26Mar2009 16:25

Re: unable to connect to the database on webserver
 
and your connection url? You have to put your mysql server url and database name and correct port.
Code:

String connectionURL = "jdbc:mysql://IPaddress:3306/student";

painamrata 26Mar2009 16:42

Re: unable to connect to the database on webserver
 
yess...i have done the required..

painamrata 28Mar2009 09:59

Re: unable to connect to the database on webserver
 
but sill its not connecting..could u please explain it in detail..assuming i dnt know anything

painamrata 31Mar2009 10:09

Re: unable to connect to the database on webserver
 
please can any one help???

painamrata 31Mar2009 10:16

Re: unable to connect to the database on webserver
 
String connectionURL = "jdbc:mysql://IPaddress:3306/student";
i mean in this there is some problem.. is the prot number correct ?how do i find out..which one to put?

painamrata 31Mar2009 10:21

Re: unable to connect to the database on webserver
 
port*


All times are GMT +5.5. The time now is 02:18.