Results 1 to 3 of 3
  1. #1
    b01g is offline Member
    Join Date
    Jan 2011
    Posts
    7
    Rep Power
    0

    Exclamation Try to help, please

    Hi all,
    In Eclipse a choosed new -> Dynamic Web Project. Then I selected tomcat (as runtime) and jdk. Next, created a jsp file, named index.
    Java Code:
    <%@ page language="java" import="java.sql.*" %>
    <html>
    <body>
    <%!
    String username = "catalog_dev";
    String password = "dev_catalog";
    String database = "catalog";
    %>
    <%
    try{
    	Class.forName("com.mysql.jdbc.Driver");
    	String url = "jdbc:mysql://localhost:3306/" + database;
    	Connection con = DriverManager.getConnection(url, username, password);
    	Statement stmt;
    	stmt = con.createStatement();
    	ResultSet rs;
    	rs = stmt.executeQuery("select * from catalog;");
    	while(rs.next()){
    		int id = rs.getInt("id");
    		String name = rs.getString("name");
    		String location = rs.getString("location");
    		int marker = rs.getInt("marker");
    	%>
    	<%= Int01 %>
    	<%
     }
    	rs.close();
    	stmt.close();
    	con.close();
    
    }
    catch(Exception e) {
    	e.printStackTrace();
    }
    %>
    Test !
    </body>
    </html>
    I want, to connect to MySQL, and retrieve the data. I have already created a table named "catalog" under a database named "catalog" and filled it with data. Table columns are id(int), name (varchar), location (varchar) and marker(boolean). When are run it, i get on the browser screen only "Test!". Why it doesn't print "Int01" value ?
    In the console i get :
    Java Code:
    java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
    	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1643)
    	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1488)
    	at org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:126)
    	at org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:63)
    	at java.lang.Class.forName0(Native Method)
    	at java.lang.Class.forName(Class.java:169)
    	at org.apache.jsp.index_jsp._jspService(index_jsp.java:66)
    	at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    	at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:417)
    	at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391)
    	at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:306)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
    	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
    	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:550)
    	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:380)
    	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:243)
    	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
    	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:166)
    	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:288)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    	at java.lang.Thread.run(Thread.java:662)
    I'll appreciate any help. Thnx in advance.
    P.S: Sorry for my english.
    Last edited by b01g; 01-29-2011 at 09:16 PM.

  2. #2
    b01g is offline Member
    Join Date
    Jan 2011
    Posts
    7
    Rep Power
    0

    Default

    It works now, thnx anyway.

  3. #3
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,805
    Rep Power
    19

    Default

    I realise it works, but a word of advice. DB stuff should not be done in a JSP.
    Get the data in a Servlet and then forward to a JSP for display.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •