guys i m really havin hard time to establish connection bet jsp n mysql...give me some tips..i ve done all the procedures required for that n i couldn execute the followin code

<%@ page import="java.sql.*" %>
<%
String username="mahesh";
String password="mahesh";
String connectionURL = "jdbc:mysql://localhost:3306/mahesh";
Connection connection = null;
//Statement statement = null;
//ResultSet rs = null;
%>

<html><body>

<%
Class.forName("com.mysql.jdbc.Driver").newInstance();
connection = DriverManager.getConnection(connectionURL, username, password);
//statement = connection.createStatement();
out.println("connection established");
//rs = statement.executeQuery("SELECT * FROM cust2");

/*while (rs.next()) {
out.println(rs.getString("name")+"<br>");
}*/


//rs.close();
%>

</body></html>

never bet, it doesn't pay in the long run.

never do database access from jsp, it's not what they're meant for (yes, I know it's possible but it's also possible to jump off a 50 story building).

and always use code tags.

Verify you have the MySqlConnector.jar in your Project Folder.If not download it from google.com and add to project Folder.or Library Location of your IDE.check Whether MySql Service is running properly by Log in into MySql Client.IF Running Properly

Class.forName("com.mysql.jdbc.Driver");
                String  url1="jdbc:mysql://127.0.0.1:3306/ek";
                Connection con1=null;
ResultSet rs=null;
                con1=DriverManager.getConnection(url1,"mahesh","mahesh");
                pstmt3=con1.prepareStatement("SELECT * FROM cust2");
              rs=pstmt3.executeQuery();
 while(rs.next())
{
System.out.println(rs.getString("name");
out.println(rs.getString("name")+"<br>");
}

If not Ur MySql Login has some Problem

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.