1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

unable to connect to the database on webserver

Discussion in 'MySQL' started by painamrata, Mar 26, 2009.

  1. painamrata

    painamrata New Member

    Joined:
    Mar 26, 2009
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    0
    :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></b>
     
    Company Address : <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<%=scadd%><br><br></b>
     
    Zipcode : <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<%=szipcode%><br><br></b>
     
    Phoneno : <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<%=sphone%><br><br></b>
     
    Emailadd : <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<%=semail%><br><br></b>
    </td>
     
    </tr>
    </table>
    </center>
    <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&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>
     
    Last edited by a moderator: Mar 26, 2009
  2. coderzone

    coderzone Super Moderator

    Joined:
    Jul 25, 2004
    Messages:
    734
    Likes Received:
    37
    Trophy Points:
    0
    are you sure the username/password on your server is correct?
     
  3. painamrata

    painamrata New Member

    Joined:
    Mar 26, 2009
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    0
    yes it is...i checked it agian..
     
  4. painamrata

    painamrata New Member

    Joined:
    Mar 26, 2009
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    0
    we should put the user name and password of the mysql server right..m using putty..
     
  5. coderzone

    coderzone Super Moderator

    Joined:
    Jul 25, 2004
    Messages:
    734
    Likes Received:
    37
    Trophy Points:
    0
    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";
    
     
  6. painamrata

    painamrata New Member

    Joined:
    Mar 26, 2009
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    0
    yess...i have done the required..
     
  7. painamrata

    painamrata New Member

    Joined:
    Mar 26, 2009
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    0
    but sill its not connecting..could u please explain it in detail..assuming i dnt know anything
     
  8. painamrata

    painamrata New Member

    Joined:
    Mar 26, 2009
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    0
    please can any one help???
     
  9. painamrata

    painamrata New Member

    Joined:
    Mar 26, 2009
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    0
    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?
     
  10. painamrata

    painamrata New Member

    Joined:
    Mar 26, 2009
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    0
  11. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,276
    Likes Received:
    364
    Trophy Points:
    83
    Edit the posts and not post again and again as you should have the needed permission now.
     
  12. vikas1234

    vikas1234 New Member

    Joined:
    Aug 21, 2008
    Messages:
    18
    Likes Received:
    0
    Trophy Points:
    0
    wats is the value of IPaddress .. are you passing it correctly ??
     

Share This Page