Solved

Need Help with jsp in Eclipse talking to MySQL database

Posted on 2007-11-24
2
1,094 Views
Last Modified: 2013-12-02
I have this skeleton Framework for a jsp server app in Eclipse running tomcat 6.x and external MySQL server.

After some initial tweaking this seems to at least run without errors, suggesting that I am connecting to the database.  I did, however, have to add the following two .jar files to the Referenced Libraries path in my project.  Is it normal to have to do that?  Can I not add these to the eclipse libraries or plug-ins so that I won't have to add them for each application that uses MySQL, and why do I have to add aspectj-1.5.3.jar.  It seems that this is necessary.

mysql-connector-java-5.1.5-bin.jar
aspectj-1.5.3.jar

My main question is:

How can I verify that the database connection is working and what other code can I use to test the driver (i.e. insert, removing, joining, etc).  With the way I have it configured it seems to be connecting but I'm not getting any output despite a non-empty database.

I do have the ability to create and manipulate a database using phpmyadmin or similar tool, so I would appreciate some instructions on how to set up a test database and how to access it via the .jsp page using struts and or java code.

Thanks.
<%@ page language="java" import="java.sql.*" pageEncoding="UTF-8"%>
<%
Class.forName("com.mysql.jdbc.Driver").newInstance(); 
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/confluence","user","pass");
Statement stmt = con.createStatement();  
String query = "SELECT * from content"; 
ResultSet rs = stmt.executeQuery(query); 
System.out.println(rs); 
while (rs.next()) { 
String s = rs.getString("CONTENTTYPE"); 
System.out.println(s); 
}
%>    
<%String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'index.jsp' starting page</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
  </head>
  
  <body>
    This is my JSP page. <br>
  </body>
</html>

Open in new window

0
Comment
Question by:sscotti
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 17

Accepted Solution

by:
contactkarthi earned 500 total points
ID: 20355764
instead of System.out.println give out.println so that you can see the output in jsp

here is a link for a good tutorial on Struts
http://www.roseindia.net/struts/
0
 
LVL 5

Author Closing Comment

by:sscotti
ID: 31410830
Not quite what I was looking for but it helped.  I can use the struts reference and I was able to figure it out.  
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
jmss example java 2 35
how to access a remote mysql database with xampp 3 43
junit as external jar or library 7 40
WordPress  Failed to Import Media 6 12
Foreword In the years since this article was written, numerous hacking attacks have targeted password-protected web sites.  The storage of client passwords has become a subject of much discussion, some of it useful and some of it misguided.  Of cou…
Creating and Managing Databases with phpMyAdmin in cPanel.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question