Results 1 to 3 of 3
  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
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,651
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by pranjul137 View Post
    but it give exception:java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

    what sholud i do..??
    The answers were already given to you in your other (identical) thread. Don't just start new threads while you haven't even responded to the answers in your previous thread.

    kind regards,

    Jos

  3. #3
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    6

    Default

    Quote Originally Posted by pranjul137 View Post
    what sholud i do..??

    make sure that your mysql-connector-java-x.x.x-bin.jar is in the classpath. in addition i specify the connection with portnumber and schema. here is my code i usually use to connect to mysql

    Java Code:
    		if (connection == null) {
    			try {
    				Class.forName("com.mysql.jdbc.Driver");
    			} catch (ClassNotFoundException e) {
    				System.out.println("Couldn't find the driver!");
    				e.printStackTrace();
    				System.exit(1);
    			}
    
    			try {
    				connection = DriverManager.getConnection(
    						"jdbc:mysql://localhost:3306/mydb", userID, passwd);
    			} catch (Throwable e) {
    				System.out.println("Couldn't get connection to localhost!");
    				e.printStackTrace();
    				System.exit(1);
    			}
    		}

Similar Threads

  1. connection my mysql in jsp in myeclipse
    By pranjul137 in forum New To Java
    Replies: 12
    Last Post: 02-03-2014, 02:43 PM
  2. connection my mysql
    By pranjul137 in forum New To Java
    Replies: 5
    Last Post: 04-06-2010, 08:26 PM
  3. TWO IPs FOR MY MYSQL CONNECTION
    By tugalsan in forum JDBC
    Replies: 2
    Last Post: 03-21-2010, 08:46 PM
  4. Java-mysql connection
    By Kligham in forum New To Java
    Replies: 16
    Last Post: 11-25-2009, 01:28 PM
  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
  •