5 Replies Latest reply on Jun 11, 2012 5:24 PM by mikemil

    com.mysql.jdbc.Driver is not found.

    samwun9988

      Hi, I have written a WEB-INF/testdb.jsp file with a direct call to mysql driver, but jboss cannot find its driver.

      Here is the content of jsp file:

       

       

      <%@page import="java.sql.*,java.io.*"%>

      <%

      try{

          InputStream sImage;

          Class.forName("com.mysql.jdbc.Driver");

          Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/houseware","root","xxx");

            Statement st=con.createStatement();

            ResultSet rs=st.executeQuery("SELECT image_data FROM category_images");

            if(rs.last()) {

            byte[] bytearray = new byte[1048576];

            int size=0;

            sImage = rs.getBinaryStream(1);

            response.reset();

            response.setContentType("image/jpeg");

            while((size=sImage.read(bytearray))!= -1 ){

            response.getOutputStream().write(bytearray,0,size);

         }

      }

      con.close();

      }    

      catch(Exception ex){

      out.println("error :"+ex);

      }

      %>

       

       

      Any suggestion is very appreciated.

      Thanks

      Sam

        • 1. Re: com.mysql.jdbc.Driver is not found.
          ctomc

          and where is your driver?

          • 2. Re: com.mysql.jdbc.Driver is not found.
            samwun9988

            Hi thank you for your reply.

            Here is where I installed mysql driver:

             

             

            find . -name "mysql*"

            ./modules/com/mysql

            ./modules/com/mysql/main/mysql-connector-java-5.1.15.jar

            ./modules/com/mysql/main/mysql-connector-java-5.1.15.jar.index

            ./standalone/tmp/vfs/temp12f1608b639591bf/spring-hibernate-mysql.war-ae1470f21011bb7a/WEB-INF/lib/mysql-connector-java-5.1.14.jar

            ./standalone/tmp/vfs/deployment52686ab5ad56ccec/mysql-connector-java-5.1.14.jar-e78d9b932564537f

            ./standalone/tmp/vfs/deployment52686ab5ad56ccec/mysql-connector-java-5.1.14.jar-e78d9b932564537f/mysql-connector-java-5.1.14.jar

             

            Thanks

            Sam

            • 3. Re: com.mysql.jdbc.Driver is not found.
              ctomc

              Hi,

               

              why don't you create datasource and then just lookup it up in jndi.

              this case you do not need to use mysql jdbc driver directly in your code.

               

              if you still wan't to use jdbc driver in your code you need to add dependancy to it in MANIFEST.MF or jboss-deployment-structure.xml

               

              for more info how to do this, please read https://docs.jboss.org/author/display/AS71/Class+Loading+in+AS7

               

               

              --

              tomaz

              • 4. Re: com.mysql.jdbc.Driver is not found.
                samwun9988

                Hi thanks for the suggestion.

                I have got the driver resolved.

                Now I encountered another error:

                 

                 

                error :java.lang.IllegalStateException

                 

                the above error is caused by the following statement in my jsp file:

                 

                 

                OutputStream os = response.getOutputStream();

                         os.write(bytearray,0,size);

                         os.flush();

                 

                 

                Full jsp code is:

                 

                 

                <%@page import="java.sql.*,java.io.*"%>

                <%

                byte[] bytearray = null;

                try{

                    InputStream sImage;

                    Class.forName("com.mysql.jdbc.Driver");

                    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/houseware","root","xxx");

                      Statement st=con.createStatement();

                      ResultSet rs=st.executeQuery("SELECT image_data FROM category_images WHERE category_id=4957");

                      out.println(" -- before rs.last() --");

                      if(rs.last()) {

                            bytearray = new byte[1048576];

                            int size=0;

                            sImage = rs.getBinaryStream(1);

                            response.reset();

                            response.setContentType("image/jpeg");

                            out.println("--- before while() --- ");

                            while((size=sImage.read(bytearray))!= -1 ) {

                                out.println("-- in while() --");

                                OutputStream os = response.getOutputStream();

                                os.write(bytearray,0,size);

                                os.flush();

                            }

                      }

                      con.close();

                }    

                    catch(Exception ex){

                    out.println("bytearray:"+bytearray.length);

                    out.println("error :"+ex);

                }

                %>

                 

                 

                Thanks

                Samuel

                • 5. Re: com.mysql.jdbc.Driver is not found.
                  mikemil

                  Take a look here https://community.jboss.org/wiki/DataSourceConfigurationInAS7

                   

                  I was able to drop the MySQL 5.1.20 into my 7.1.1.Final standalone\deployments folder and get it working - because it has the META-INF\services\java.sql.Driver file included.