RE: MYSQL and TOMCAT

2003-03-25 Thread Ralph Einfeldt
First of all you shouldn't rethrow the exception.
That hides the true nature of the problem.

 -Original Message-
 From: jsp [mailto:[EMAIL PROTECTED]
 Sent: Tuesday, March 25, 2003 4:17 AM
 To: 'Tomcat Users List'
 Subject: MYSQL and TOMCAT
 
PreparedStatement updateInfo;
updateInfo = con.prepareStatement(
 insert into info(?););
updateInfo.setString(1,Referer);
updateInfo.execute();
 
 }
catch (SQLException sqle) {
   error = Update failed, possible duplicate entry;
   throw new SQLException( error );
}
  } 

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: MYSQL and TOMCAT

2003-03-25 Thread Ramiro Gonzalez
What  I see

your are losing the real message of the error:

  catch (SQLException sqle) {
 error = Update failed, possible duplicate entry;
 throw new SQLException( error );
  }
Better you should do:

  catch (SQLException sqle) {
   System.out.println(sqle.getMessage()); //get the message from 
the exception
 // do something here to return the error upside
  }


jsp wrote:

Here is another beginner question of sorts I imagine.
I receive this error.
java.sql.SQLException: Update failed, possible duplicate entry


I've got this code in a .jsp page.

% String ref=request.getHeader(Referer);%
BR
% 
	count.addInfo( ref );
%

count is calling the method addInfo
in a java bean...
public void addInfo( String Referer )
 throws SQLException, Exception {
if (con != null) {
   try{
   
  PreparedStatement updateInfo;
  updateInfo = con.prepareStatement(
   insert into info(?););
  updateInfo.setString(1,Referer);
  updateInfo.execute();
   
   }
  catch (SQLException sqle) {
 error = Update failed, possible duplicate entry;
 throw new SQLException( error );
  }
} 
else {
   error = Connection with database was lost.;
   throw new Exception( error );
}
 }

Can anyone see the mistake I am making here. My database has one table
now called info with one String field which is the primary key also.
Thanks if anyone can help or point me to a webpage or something.

-wiley



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 





-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: MYSQL and TOMCAT

2003-03-24 Thread Kwok Peng Tuck
java.sql.SQLException: Update failed, possible duplicate entry

Let's see you have a table info with one field and that field is a primary key right? 
If I remember correctly, primary keys in a table have to be unique, so maybe you are calling
your method with the same data again and again ? 



 



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Mysql and Tomcat

2002-04-15 Thread Andy Eastham

Gareth,

What are the errors?

We're running mysql under Tomcat and our corresponding code is:
Class.forName(org.gjt.mm.mysql.Driver).newInstance();
this.connection = DriverManager.getConnection(jdbc:mysql:// +
this.databaseHost +: + this.databasePort + / + this.databaseName +
?user= + this.databaseUsername + password= + this.databasePassword);

This works fine, but I guess it's more likely a class loading problem you're
having.  I'd check that mysql.jar is under Tomcat/common/lib.  We've also
got jdbc2_0-stdext.jar there, although I'm not sure this is required any
more.

Andy

 -Original Message-
 From: Lawrence, Gareth [mailto:[EMAIL PROTECTED]]
 Sent: 15 April 2002 05:53
 To: 'Tomcat Users List'
 Subject: Mysql and Tomcat


 Greetings All,

 Just when I though everything was sweet I'm having a nasty
 problem.  I'm running:
 Debian Linux, Tomcat 4.0.3, Mysql, Ant, MM JDBC driver.

 Basically I've set everything up sweet and when I run a test file
 from the command line (java test.class) I get a connection to the
 database no problems.  Unfortunately when I try and do the same
 thing through a servlet loaded onto Tomcat I get grief!!!  See below
 I get two errors outputted in the browser window, the second one
 could be caused by the first :-)

 If anyway has any ideas about this, please let me know this is a
 desperate one :-(((

 Thanks heaps and heaps,

 Gareth

 Code:

 try {
 //Registering the MySQL JDBC Driver
 Class.forName(org.gjt.mm.mysql.Driver).newInstance();
 }
 catch (Exception E) {
 out.println(pException: Created Driver/p);
 System.err.println(Unable to load driver.);
 E.printStackTrace();
 }

 try {
 //create variable url containing connecting value
 String url=jdbc:mysql://localhost/weblearn;
 //Create Connection Object from java.sql.*
 Connection Conn = DriverManager.getConnection(url, root, );
 }
 //Exceptions if something went wrong
 catch (SQLException E) {
 out.println(pSQL Exception/p);
 }






--
To unsubscribe:   mailto:[EMAIL PROTECTED]
For additional commands: mailto:[EMAIL PROTECTED]
Troubles with the list: mailto:[EMAIL PROTECTED]