national Posted September 16, 2013 Posted September 16, 2013 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 Quote
national Posted September 17, 2013 Author Posted September 17, 2013 Please install mysql connector or JLibrary in my account because it's giving me error ClassNotFoundExceptionwhenever I want to connect to the databaseMy domain name is nationalautomobiles.heliohost.orgid is national Quote
Ice IT Support Posted September 17, 2013 Posted September 17, 2013 Others have been able to connect just fine to MySQL through Java. If you post the code you are using we can perhaps suggest an alternative connection method. Quote
national Posted September 18, 2013 Author Posted September 18, 2013 <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 Quote
Ice IT Support Posted September 19, 2013 Posted September 19, 2013 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 Quote
national Posted September 20, 2013 Author Posted September 20, 2013 <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> Quote
national Posted September 21, 2013 Author Posted September 21, 2013 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" Quote
national Posted September 22, 2013 Author Posted September 22, 2013 Is there anyone in Heliohost who can solve my Problem ??? Quote
rohanawaw Posted June 5, 2017 Posted June 5, 2017 put mysql connector jar in web-inf /lib directory Quote
Krydos Posted June 5, 2017 Posted June 5, 2017 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.