: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> </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> <%=ssub%> <br> <br></b></font> Enquiry Details : <b> <%=senq%><br><br></b> Firstname : <b> <%=sfname%><br><br></b> Lastname : <b> <%=slname%><br><br></b> Company Name : <b> <%=scname%><br><br></b> Company Address : <b> <%=scadd%><br><br></b> Zipcode : <b> <%=szipcode%><br><br></b> Phoneno : <b> <%=sphone%><br><br></b> Emailadd : <b> <%=semail%><br><br></b> </td> </tr> </table> </center> <p> <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>
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";
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?