The problem was my PRIMARY KEY, it was not auto_incrementing among other
things. This is the method that works now.

public void addInfo( java.lang.Integer i , String s )
      throws SQLException, Exception {
      
         if (con != null) {
            try{
            
               Statement info = con.createStatement();
            
               String insert = "INSERT into info VALUES (NULL,'" + s +
"','" + i + "')";
            
               info.executeUpdate( insert );    
            
            
            
            }
               catch (SQLException sqle) {
                  error ="An error occured";
                  throw new SQLException( error );
               
               }
         
         }


One more question for you though. Is it possible to ADD "i" to the
preceding value of the field inside mysql each time the method is
called, making the new method "i + i" does that make sense ?


Anyway thanks
-wiley





-----Original Message-----
From: Kyle Lange [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, March 25, 2003 1:43 AM
To: 'jsp'; 'Tomcat Users List'
Cc: [EMAIL PROTECTED]
Subject: RE: Cannot Update MYSQL Database

I think you probably need to do one of the following;

Insert into info set referer = ?

Or

Insert into info (referer) values (?)

But I could be wrong. 



-----Original Message-----
From: jsp [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, 25 March 2003 07:17
To: 'Tomcat Users List'
Cc: [EMAIL PROTECTED]
Subject: Cannot Update MYSQL Database


I'm running this code with no errors but it's not inserting the string
into the database ?

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){ 
                  sqle.printStackTrace();
               }
         }
         else {
            error = "Connection with database was lost.";
            throw new Exception( error );
         }
      }

This is my database
mysql> desc info;
+---------+-----------+------+-----+---------+-------+
| Field   | Type      | Null | Key | Default | Extra |
+---------+-----------+------+-----+---------+-------+
| ID      | int(11)   |      | PRI | 0       |       |
| REFERER | char(200) | YES  |     | NULL    |       |
+---------+-----------+------+-----+---------+-------+
2 rows in set (0.00 sec)

Any Idea why nothing is showing up. Referer is a String its printing out
on the page but not updating the database?

Thanks anyone
-wiley

   


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:
http://lists.mysql.com/[EMAIL PROTECTED]


---------------------------------------------------------------------
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]

Reply via email to