Results 1 to 13 of 13
  1. #1
    pranjul137 is offline Member
    Join Date
    Apr 2010
    Posts
    13
    Rep Power
    0

    Default connection my mysql in jsp in myeclipse

    I am trying to execute following code:
    <%@ page import="java.sql.*" %>
    <%
    String connectionURL= "jdbc:mysql://localhost:java";
    Connection conn = null;
    Statement stmt = null;
    ResultSet rs =null;
    String Username="root";
    String Pass = "";

    %>
    <html>
    <body>
    <%
    try{
    Class.forName ("com.mysql.jdbc.Driver").newInstance ();

    conn = DriverManager.getConnection(connectionURL,Username ,Pass);
    String sqlselect = "Select * from `java`.hrms_login_user ";
    stmt = conn.createStatement();
    stmt.executeQuery(sqlselect);
    rs = stmt.getResultSet();
    while(rs.next()){
    String a = rs.getString("USER_NAME");
    System.out.println(a);

    }
    }catch(Exception e){
    e.printStackTrace();
    }
    %>
    </body>

    </html>

    but it give exception:java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

    what sholud i do..??

  2. #2
    PhQ's Avatar
    PhQ
    PhQ is offline Senior Member
    Join Date
    Mar 2010
    Location
    Lithuania
    Posts
    358
    Rep Power
    5

    Default

    You need a MySQL library.

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default

    First off don't do this sort of thing in a JSP...that's what servlets and database layers are for. JSP are for displaying things.

    Second, learn SQL...that select and then looping through the resultset offends the eye...;)

    And finally, that error means you haven't got the drivers jar file in the classpath of wherever it is you're running this.

  4. #4
    pranjul137 is offline Member
    Join Date
    Apr 2010
    Posts
    13
    Rep Power
    0

    Default

    thanks for your reply......but in myeclipse if i execute the code in simple java file then connection to mysql is establish then why not with jsp??

  5. #5
    pranjul137 is offline Member
    Join Date
    Apr 2010
    Posts
    13
    Rep Power
    0

    Default

    i am also using Mysql-connector-java version 5.0.7

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default

    Myeclipse knows where the jar file is, since it used it to build the code, so running straight java is a doddle for it.

    When you're running the JSP it will use a server (Tomcat maybe?) to run it, deploying your app to that server...if it fails to deploy (for whatever reason) the jar file then you get that exception.

  7. #7
    pranjul137 is offline Member
    Join Date
    Apr 2010
    Posts
    13
    Rep Power
    0

    Default

    ok...then how can i deploy the jar file in myeclipse....i used
    Project's context-menu select Properties > Java Build Path >Libraries the add mysql-connector-java-5.1.6.jar

  8. #8
    pranjul137 is offline Member
    Join Date
    Apr 2010
    Posts
    13
    Rep Power
    0

    Default

    i just want to run a web application on myeclipse and connect to mysql database...please resolve my problem..

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default

    I would suggest looking through the documentation.
    You want to deploy the jar when the web app is deployed...having it in the build path is no use to the JSP, which is translated into a java class and then compiled on the server, not in your IDE.

    So dig out the docs.

  10. #10
    atulkushwaha is offline Member
    Join Date
    Feb 2014
    Posts
    1
    Rep Power
    0

    Default Re: connection my mysql in jsp in myeclipse

    ok pranjul. have you copied jdbc.jar file in your eclipse library?? if not then copy this file.

  11. #11
    superhaNds is offline Senior Member
    Join Date
    Apr 2013
    Location
    Sweden
    Posts
    264
    Rep Power
    2

    Default Re: connection my mysql in jsp in myeclipse

    Quote Originally Posted by atulkushwaha View Post
    ok pranjul. have you copied jdbc.jar file in your eclipse library?? if not then copy this file.
    OK, I understand that you were probably a necromancer in Skyrim, but stick with it only in the game.

  12. #12
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,876
    Rep Power
    5

    Default Re: connection my mysql in jsp in myeclipse

    lol, took me a while to understand that one :) Being a long time player of the game myself I was reasoning from the perspective of necromancers being the most useless character to play in the game rather than just assuming thread necro :)
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  13. #13
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,436
    Blog Entries
    7
    Rep Power
    20

    Default Re: connection my mysql in jsp in myeclipse

    I'm closing this thread; it smells funny in here ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. connection my mysql
    By pranjul137 in forum New To Java
    Replies: 5
    Last Post: 04-06-2010, 08:26 PM
  2. TWO IPs FOR MY MYSQL CONNECTION
    By tugalsan in forum JDBC
    Replies: 2
    Last Post: 03-21-2010, 08:46 PM
  3. Java-mysql connection
    By Kligham in forum New To Java
    Replies: 16
    Last Post: 11-25-2009, 01:28 PM
  4. java mysql connection
    By sysout in forum New To Java
    Replies: 5
    Last Post: 10-31-2009, 10:48 AM
  5. no mysql connection
    By scchia in forum New To Java
    Replies: 12
    Last Post: 07-19-2008, 07:57 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
  •