Results 1 to 9 of 9
- 04-08-2010, 07:54 PM #1
Member
- Join Date
- Apr 2010
- Posts
- 13
- Rep Power
- 0
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..??
- 04-08-2010, 08:20 PM #2
You need a MySQL library.
- 04-08-2010, 08:21 PM #3
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
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.
- 04-09-2010, 02:05 PM #4
Member
- Join Date
- Apr 2010
- Posts
- 13
- Rep Power
- 0
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??
- 04-09-2010, 02:08 PM #5
Member
- Join Date
- Apr 2010
- Posts
- 13
- Rep Power
- 0
i am also using Mysql-connector-java version 5.0.7
- 04-09-2010, 02:12 PM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
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.
- 04-10-2010, 12:34 PM #7
Member
- Join Date
- Apr 2010
- Posts
- 13
- Rep Power
- 0
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
- 04-10-2010, 12:46 PM #8
Member
- Join Date
- Apr 2010
- Posts
- 13
- Rep Power
- 0
i just want to run a web application on myeclipse and connect to mysql database...please resolve my problem..
- 04-12-2010, 09:47 AM #9
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Similar Threads
-
connection my mysql
By pranjul137 in forum New To JavaReplies: 5Last Post: 04-06-2010, 08:26 PM -
TWO IPs FOR MY MYSQL CONNECTION
By tugalsan in forum JDBCReplies: 2Last Post: 03-21-2010, 08:46 PM -
Java-mysql connection
By Kligham in forum New To JavaReplies: 16Last Post: 11-25-2009, 01:28 PM -
java mysql connection
By sysout in forum New To JavaReplies: 5Last Post: 10-31-2009, 10:48 AM -
no mysql connection
By scchia in forum New To JavaReplies: 12Last Post: 07-19-2008, 07:57 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks