Jump to content

How To Connect Jsp With Mysql Database In Heliohost


national

Recommended Posts

I have written the code like this

 

 

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

Connection c = DriverManager.getConnection("jdbc:mysql://localhost/national?user=root");

 

 

but it's giving me an Error like this

 

 

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

 

Please Tell me how I connect the database

Link to comment
Share on other sites

<p>ok This is my Code please see it<br />

 </p>

<div><%-- </div>

<div>    Document   : TestConnection.jsp</div>

<div>    Created on : Sep 16, 2013, 11:47:41 AM</div>

<div>    Author     : Manish Gupta</div>

<div>--%></div>

<div><%@page import="java.sql.*" %></div>

<div><%@page contentType="text/html" pageEncoding="windows-1252"%></div>

<div><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"></div>

<div><html></div>

<div>    <head></div>

<div>        <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"></div>

<div>        <title>JSP Page</title></div>

<div>    </head></div>

<div>    <body></div>

<div> </div>

<div>        <%</div>

<div>try</div>

<div>{</div>

<div>Class.forName("com.mysql.jdbc.Driver").newInstance();</div>

<div>Connection connection = DriverManager.getConnection(</div>

<div>  "jdbc:mysql://127.0.0.1/" + "my_dbname",</div>

<div>  "my_username",</div>

<div>  "my_password"</div>

<div>);</div>

<div>Statement statement = connection.createStatement();</div>

<div>ResultSet result = statement.executeQuery("SELECT * FROM adminlogin");</div>

<div>while (result.next()) { </div>

<div>%></div>

<div><%= result.getString(2) %>: <%= result.getString(3) %><br/></div>

<div><% }</div>

<div>}</div>

<div>catch(Exception e)</div>

<div>{</div>

<div>session.setAttribute("Error",e);</div>

<div>response.sendRedirect("Error.jsp");</div>

<div>}</div>

<div> %></div>

<div> </div>

<div> </div>

<div> </div>

<div> </div>

<div>    </body></div>

<div></html></div>

 

 

Please Check the Attachment

 

<%--

Document : TestConnection.jsp

Created on : Sep 16, 2013, 11:47:41 AM

Author : Manish Gupta

--%>

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

<%@page contentType="text/html" pageEncoding="windows-1252"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">

<title>JSP Page</title>

</head>

<body>

 

<%

try

{

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

Connection connection = DriverManager.getConnection(

"jdbc:mysql://127.0.0.1/" + "my_dbname",

"my_username",

"my_password"

);

Statement statement = connection.createStatement();

ResultSet result = statement.executeQuery("SELECT * FROM adminlogin");

while (result.next()) {

%>

<%= result.getString(2) %>: <%= result.getString(3) %><br/>

<% }

}

catch(Exception e)

{

session.setAttribute("Error",e);

response.sendRedirect("Error.jsp");

}

%>

 

 

 

 

</body>

</html>

 

I hope this will help

Link to comment
Share on other sites

Try this:

<%@page import="java.sql.*" %>
<%
Connection connection = DriverManager.getConnection(
 "jdbc:mysql://127.0.0.1/" + mysql_database,
 mysql_username,
 mysql_password
);
Statement statement = connection.createStatement();
ResultSet result = statement.executeQuery("SELECT username, password FROM accounts");
while (result.next()) { 
%>
<%= result.getString("username") %>: <%= result.getString("password") %><br/>
<% } %>

Source: http://www.heliohost.org/home/features/databases/mysql

Link to comment
Share on other sites

<p>It's also not working see my code </p>

<p> </p>

<div><%@page import="java.sql.*" %></div>

<div><%</div>

<div>try</div>

<div>{</div>

<div>Connection connection = DriverManager.getConnection(</div>

<div>  "jdbc:mysql://127.0.0.1/"+"national_national",</div>

<div>  "username",</div>

<div>  "password"</div>

<div>  );</div>

<div>Statement statement = connection.createStatement();</div>

<div>ResultSet result = statement.executeQuery("SELECT * from adminlogin");</div>

<div>while (result.next()) { </div>

<div>%></div>

<div><%= result.getString(2) %>: <%= result.getString(3) %><br/></div>

<div><% }</div>

<div>}</div>

<div>catch(Exception e)</div>

<div>{</div>

<div>session.setAttribute("Error",e);</div>

<div>response.sendRedirect("Error.jsp");</div>

<div>} %></div>

 

 

<p>And the Error is </p>

<p> </p>

<p> </p>

<h2 style="color: rgb(0, 0, 0); font-family: 'Times New Roman';">

Error is    java.sql.SQLException: No suitable driver found for jdbc:mysql://127.0.0.1/national_national</h2>

 

Link to comment
Share on other sites

Please tell me anyone who have connected his/her website of jsp to mysql in heliohost then please tell me that how u have get connected because I am not able to connect to the database

Everytime I try to connect to the database it's giving me error ClassNotFoundException "com.mysql.jdbc.Driver"

Link to comment
Share on other sites

  • 3 years later...

Did you notice that this thread was from almost 4 years ago? It's highly unlikely he's spent the last 4 years trying to figure it out, but I guess if anyone searches and finds this thread it is good advice.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...