i'm not able to connect to the mysql through eclipse java program(servlet)
import java.io.IOException; import java.io.PrintWriter; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; //import java.sql.SQLException; import java.sql.Statement;
import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse;
/** * Servlet implementation class DataController */ @WebServlet("/DataController") public class DataController extends HttpServlet { private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public DataController() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
PrintWriter out=response.getWriter();
Connection con=null;
String connectionURL = "jdbc:Mysql://root@127.0.0.1:3306/sakila;user=root;password=root";
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection (connectionURL);
}
catch(Exception e){
out.println("Connecction not established :"+e.getMessage());
}
try{
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select * from actor");
if(rs.next()){
out.println("<html><head></head><body>");
out.println("<h1>Hello </h1>");
out.println(rs.getString(0));
out.println("Your Password is :");
out.println(rs.getString(1));
out.println("</body></html>");
}
}
catch (Exception e) {
out.println("Unable to Retreive"+e.getMessage());
}
finally{
}
}
}
ERROR : connection not established....
25 Jan, 2013 8:58:38 PM org.apache.catalina.core.AprLifecycleListener init INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre6\bin;.;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files (x86)\Common Files\Roxio Shared\DLLShared\;C:\Program Files (x86)\Common Files\Roxio Shared\OEM\DLLShared\;C:\Program Files (x86)\Common Files\Roxio Shared\OEM\DLLShared\;C:\Program Files (x86)\Common Files\Roxio Shared\OEM\12.0\DLLShared\;C:\Program Files (x86)\Roxio\OEM\AudioCore\;c:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\DTS\Binn\ 25 Jan, 2013 8:58:38 PM org.apache.tomcat.util.digester.SetPropertiesRule begin WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:LoginApp' did not find a matching property. 25 Jan, 2013 8:58:38 PM org.apache.tomcat.util.digester.SetPropertiesRule begin WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:Database' did not find a matching property. 25 Jan, 2013 8:58:39 PM org.apache.coyote.AbstractProtocol init INFO: Initializing ProtocolHandler ["http-bio-8080"] 25 Jan, 2013 8:58:39 PM org.apache.coyote.AbstractProtocol init INFO: Initializing ProtocolHandler ["ajp-bio-8009"] 25 Jan, 2013 8:58:39 PM org.apache.catalina.startup.Catalina load INFO: Initialization processed in 1751 ms 25 Jan, 2013 8:58:39 PM org.apache.catalina.core.StandardService startInternal INFO: Starting service Catalina 25 Jan, 2013 8:58:39 PM org.apache.catalina.core.StandardEngine startInternal INFO: Starting Servlet Engine: Apache Tomcat/7.0.29 25 Jan, 2013 8:58:40 PM org.apache.coyote.AbstractProtocol start INFO: Starting ProtocolHandler ["http-bio-8080"] 25 Jan, 2013 8:58:40 PM org.apache.coyote.AbstractProtocol start INFO: Starting ProtocolHandler ["ajp-bio-8009"] 25 Jan, 2013 8:58:40 PM org.apache.catalina.startup.Catalina start INFO: Server startup in 1363 ms