• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

Tomcat - MySql - Win98 Jdbc connection = BOOM!

 
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey folks, first off let me quickly say that this is the coolest site I have ever found in my life! Ive learned more here in two weeks than I have in 6 months of school!! Keep it up. On to the dynamite. Ive just gotten Tomcat 3.2 installed & running on my win98 machine (thanks to Jimi Rock) I also have succesfully installed Mysql & have the server configured, running & tables created. I downloaded the driver & installed accordingly (I think). Im using this JdbcServletCheckup servlet that we used in school to attempt the connection between the two apps. When I call the servlet it shuts tomcat right down.........BOOM, closes the window, no errors to read..nothing. The dent in my forehead from banging my head on the desk is getting a tad big so I hope to heaven someone here knows what to do. Im used to win NT, javaweserver1.1 & Oracle 8ai so this stuff is brandy new to me. Im posting the whole code from this servlet so there isnt any confusion about what its doing. Thanks a million fold to any of you willing to help out.
/**************************************
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
public class JdbcServletCheckup extends HttpServlet {
private static void loadJDBCDriver () {
try {
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
}
catch (Exception e) {
System.err.println (e.getMessage ());
System.exit (1); // Driver error
}
}
private static Connection getConnected () {
try {
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/intLovers");
return conn;
}
catch (SQLException e) {
System.err.println (e.getMessage () ) ;
System.exit (1); // Driver failure
}
return null;// never happen
}
private static Statement makeStatement (Connection conn) {
try {
Statement stmt = conn.createStatement ();
return stmt;
}
catch (SQLException e) {
System.err.println (e.getMessage () ) ;
System.exit (2); // Driver failure
}
return null;// never happen
}
private static ResultSet openResultSet (Statement stmt, String query) {
try {
ResultSet rs = stmt.executeQuery (query);
return rs;
}
catch (SQLException e) {
System.err.println (e.getMessage () ) ;
System.exit (3); // ResultSet error
}
return null;// never happen
}
private static void processResultSet (ServletOutputStream out, ResultSet rs) {
try {
while (rs.next() ) {
out.println("Username: " +rs.getString(1) + " ");
out.println("Password: " +rs.getString(2) + " ");
out.println("Member Status: "+rs.getInt(3)+ " ");
out.println("Email Address: " +rs.getString(4)+ " ");
out.println("gender: " +rs.getInt(5)+ " ");
out.println("Verified? " +rs.getInt(6)+ " ");
out.println("sign-up date: " +rs.getString(7)+ " ");
out.println("Logged On? " +rs.getInt(8)+ " ");
}
}
catch (IOException e) {
System.err.println (e.getMessage () ) ;
System.exit (4); // Output error
}
catch (SQLException e) {
System.err.println (e.getMessage () ) ;
System.exit (5); // Processing error
}
}
private static void closeThingsDown (ResultSet rs, Statement stmt, Connection conn) {
try {
rs.close();
stmt.close ();
conn.close();
}
catch (SQLException e) {
System.err.println (e.getMessage () ) ;
System.exit (5); // Closure failure
}
}
public void doGet (HttpServletRequest request, HttpServletResponse response)
{
try {
loadJDBCDriver ();
Connection conn = getConnected ();
Statement stmt = makeStatement (conn);
response.setContentType ("text/html");
ServletOutputStream out = response.getOutputStream();
String query = "SELECT * FROM mastMem";
out.println ("<HTML><BODY>");
out.println ("<HEAD><TITLE>JDBC SERVLET TEST</TITLE></HEAD>");
ResultSet rs = openResultSet (stmt, query);
processResultSet (out, rs);// print results as xml
closeThingsDown (rs, stmt, conn);// close db stuff
out.println ("</BODY></HTML>");
}
catch (IOException e) {
System.err.println (e.getMessage () );
}
}
public void doPost (HttpServletRequest request, HttpServletResponse response) {
doGet (request, response);
}
}

[This message has been edited by DC Dalton (edited June 18, 2001).]
[This message has been edited by DC Dalton (edited June 18, 2001).]
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The first place to start would be to remove all of the System.exit() calls. In general you shouldn't need them an definitely not to that level.
My guess as to what is happening is that an Exception is occuring and gets caught, but in catching it you call System.exit() which kills the JVM and hence your entire app. At this stage the window closes down cos the application has been killed (internally) so that even if you print a stack trace it goes away with the window.
If you're just starting, possibly remove all of the error trapping and let Tomcat print them out for you. As you get used to the whole app server thing you can add some exception handling, but at the moment it seems to be causing you more problems than it's fixing.
Enjoy.
Dave
 
DC Dalton
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tried pulling out the exception handling & just decalring them as being throw but the compiler had me chasing 6 million different exceptions, especially on the LoadJDBCDriver method so I had to put a generic exception back in to cover it & a few in the doGet. Im starting to think it's in that driver loading method because of all of the weird exceptions it can throw. Anyways it still shuts tomcat right down leaving no way to see exactly what exception is occuring. Here is the new code:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
public class JdbcServletCheckup extends HttpServlet {
private static void loadJDBCDriver () {
try
{
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
}
catch (Exception e)
{
System.err.println(e.getMessage() + "\n" );
e.printStackTrace();
}
}
private static Connection getConnected () throws SQLException {
Connection conn = DriverManager.getConnection("jdbc:mysql://http://localhost:3306/intLovers");
return conn;
}
private static Statement makeStatement (Connection conn) throws SQLException {
Statement stmt = conn.createStatement ();
return stmt;
}
private static ResultSet openResultSet (Statement stmt, String query) throws SQLException {
ResultSet rs = stmt.executeQuery (query);
return rs;
}
private static void processResultSet (ServletOutputStream out, ResultSet rs) throws IOException, SQLException {
while (rs.next() ) {
out.println("Username: " + rs.getString(1) + " ");
out.println("Password: " + rs.getString(2) + " ");
out.println("Member Status: " +rs.getInt(3)+ " ");
out.println("Email Address: " +rs.getString(4)+ " ");
out.println("gender: " +rs.getInt(5)+ " ");
out.println("Verified? " +rs.getInt(6)+ " ");
out.println("sign-up date: " +rs.getString(7)+ " ");
out.println("Logged On? " +rs.getInt(8)+ " ");
}
}
private static void closeThingsDown (ResultSet rs, Statement stmt, Connection conn) throws SQLException {
rs.close();
stmt.close ();
conn.close();
}
public void doGet (HttpServletRequest request, HttpServletResponse response) {
try
{
loadJDBCDriver ();
Connection conn = getConnected ();
Statement stmt = makeStatement (conn);
response.setContentType ("text/html");
ServletOutputStream out = response.getOutputStream();
String query = "SELECT * FROM mastMem";
out.println ("<HTML><BODY>");
out.println ("<HEAD><TITLE>JDBC SERVLET TEST</TITLE></HEAD>");
ResultSet rs = openResultSet (stmt, query);
processResultSet (out, rs);// print results as xml
closeThingsDown (rs, stmt, conn);// close db stuff
out.println ("</BODY></HTML>");
}
catch (IOException e)
{
System.err.println(e.getMessage() + "\n");
e.printStackTrace();
}
catch (SQLException e)
{
System.err.println(e.getMessage() + "\n");
e.printStackTrace();
}
}
public void doPost (HttpServletRequest request, HttpServletResponse response) {
doGet (request, response);
}
}
 
DC Dalton
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the help but I figured it out........seems the driver .jar files werent being picked up so I re-unzipped them & double checked the classpath...........works like a dream now. I guess not being able to find the driver & load it is a critical enough error to shut tomcat right down......Thanks again for the help.......Dave
 
If you open the box, you will find Heisenberg strangling Shrodenger's cat. And waving this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic