Results 1 to 9 of 9
  1. #1
    Join Date
    Mar 2008
    Posts
    25
    Rep Power
    0

    Default [SOLVED] mysql problem using eclipse

    hello everybody,

    i'm having trouble geeting results back from mysql server through eclipse. i know it works and code is fine however i cant get the results to show in eclipse.


    Servlet code:

    Java Code:
    package staffPackage;
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.util.*;
    import java.sql.*;
    
    import java.io.IOException;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    /**
     * Servlet implementation class DisplayEmployees
     */
    public class DisplayEmployees extends HttpServlet {
    	private static final long serialVersionUID = 1L;
           
        /**
         * @see HttpServlet#HttpServlet()
         */
        public DisplayEmployees() {
            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
    		//super.doGet(request, response);
    		
    		Connection conn =null; // Create connection object
    		String database = "NotForYourEyes"; // Name of database
    		String user = "NotForYourEyes"; // 
    		String password = "NotForYourEyes";
    		String url = "NotForYourEyes" + database;
    
    		String docType =
    		    "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 "+
    		    "Transitional//EN\"\n" +
    		    "\">";
    
    		response.setContentType("text/html"); 
    		PrintWriter out = response.getWriter();
    		out.println(docType);
    
    		try{
    		    Class.forName("com.mysql.jdbc.Driver").newInstance();
    		} catch(Exception e) {
    		    System.err.println(e);
    		}
    		
    		// connecting to database
    		 try
    		 {
    		    conn = DriverManager.getConnection(url, user, password);
    		    //String selectSQL = "select * from students,degrees WHERE students.degreecode = degrees.degreecode";
    		    String selectSQL = "select * from Staff";
    		    
    		    System.err.println("DEBUG: Query: " + selectSQL);
    		    Statement stmt = conn.createStatement();
    		    ResultSet rs1 = stmt.executeQuery(selectSQL);
    
    
    		 out.println("<Center><H1>List of Staff Members</Center>");
    		// print out table header
    		out.println("<table border=\"1\" cellspacing=\"5\" cellpadding=\"5\">" +
    			    "<tr><th>Staff ID</th><th>Surname</th><th>Forename</th><th>Current Work Status</th></tr>" );
    			   
    			while(rs1.next()){
    			    out.print("<tr>");
    			    out.print("<td>" + rs1.getString("StaffID") + "</td>");
    			    out.print("<td>" + rs1.getString("surname") + "</td>");
    			   out.print("<td>" + rs1.getString("forename") + "</td>");
    			   out.print("<td>" + rs1.getString("currentWorkStatus") + "</td>");		   
    			}		   		 
    		    
    		    }
    		    catch(SQLException e)
    		    {
    		    System.err.println(e);
    		    }
    		//print out table rows one for each row returned in rs1
    		
    		//Close table
    		out.println("</table>");
    		//CLose HTML 
    		out.println("</body></head>");
    
    	}
    
    }
    and the error message is:
    java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
    java.sql.SQLException: No suitable driver found for jdbc....(address)

    i'm guessing a plugin is need or a path of somesort, any ideas?

  2. #2
    serjant's Avatar
    serjant is offline Senior Member
    Join Date
    Jun 2008
    Location
    Ukraine,Zaporozhye
    Posts
    487
    Rep Power
    7

    Default

    First of all open the mysql config file - my.cnf and delete the line:
    Java Code:
    skip-networking
    Post here what libs of MySQL do you use to run the code

  3. #3
    Join Date
    Mar 2008
    Posts
    25
    Rep Power
    0

    Default

    i'm using - mysql-connector-java-5.0.8 (not 100% its the right plugin?)and there is no file called my.cnf? i'm also using tomcat 6 withing eclipse in windows. im not really sure how to get a list of my plugins. also i managed to get the quantum db plugin working so it is possible to connect to the mysql db. when i try to connect i still get error:
    java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
    Error in java.sql.SQLException: No suitable driver found for jdbc:mysql://...address

  4. #4
    Join Date
    Mar 2008
    Posts
    25
    Rep Power
    0

    Default

    or if any body has a working sample that works through eclipse with plugins used would be helpfull. thanks

  5. #5
    serjant's Avatar
    serjant is offline Senior Member
    Join Date
    Jun 2008
    Location
    Ukraine,Zaporozhye
    Posts
    487
    Rep Power
    7

    Default

    my.cnf file is a MySQL configuration file in the path, where you installed MySQL

  6. #6
    serjant's Avatar
    serjant is offline Senior Member
    Join Date
    Jun 2008
    Location
    Ukraine,Zaporozhye
    Posts
    487
    Rep Power
    7

    Default

    Then put mysql-connector-java-5.0.8.jar into the tomcat libs folder

  7. #7
    Join Date
    Mar 2008
    Posts
    25
    Rep Power
    0

    Default

    i dont have anything for mysql installed that has my.cnf in it. i've moved th mysql-connector jar to tomcat and i dont get any error messages but nothing happens so i guess were oon the right track

  8. #8
    Join Date
    Mar 2008
    Posts
    25
    Rep Power
    0

    Default

    thank you very much serjant,

    this was it:

    Quote Originally Posted by serjant View Post
    Then put mysql-connector-java-5.0.8.jar into the tomcat libs folder
    because i had many files open and ports it wasnt liking it...but it all worked after a good ol system restart.

    you help is much appreciated

  9. #9
    serjant's Avatar
    serjant is offline Senior Member
    Join Date
    Jun 2008
    Location
    Ukraine,Zaporozhye
    Posts
    487
    Rep Power
    7

Similar Threads

  1. Connector J with Eclipse and MySQL 5.0.x
    By int80 in forum Eclipse
    Replies: 11
    Last Post: 05-31-2010, 10:32 AM
  2. How to access MySQL Database in Eclipse 3.2
    By nijava in forum Eclipse
    Replies: 2
    Last Post: 12-12-2008, 04:04 PM
  3. Eclipse / Mysql problem
    By jdevm in forum Eclipse
    Replies: 0
    Last Post: 10-09-2008, 02:16 AM
  4. mysql driver problem
    By mokingsu in forum JDBC
    Replies: 4
    Last Post: 01-17-2008, 06:27 PM
  5. Mysql problem
    By Nick15 in forum JDBC
    Replies: 2
    Last Post: 05-15-2007, 06:07 PM

Posting Permissions

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