Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

.class expected error...

843854Dec 9 2003 — edited Dec 9 2003
Hi,

Im getting a ".class expected" error in the following code and I can't really understand why.
/* First I insert a "Kund" (customer in english but that doesn't matter) */
import java.sql.*;

public class DBHanterare {
    

    SQLHanterare sqlHanteraren = new SQLHanterare();  //handles SQL statements


    public DBHanterare() {
        
    }
    
    public int spara( Kund kund) {
        String sqlCommand= "INSERT INTO Kunder (Fnamn,Enamn,Gata,Postnr,Ort,Telnr,Epost)" + 
                           "VALUES('" + kund.fnamn + "','" + kund.enamn + "','" + kund.gata + "','" +
                            kund.postnr + "','" + kund.ort + "','" + kund.telnr + "','"  + kund.epost +"')";
         
        sqlHanteraren.update(sqlCommand); 


        /* then I wish to select the "KundID" from the latest entered post with a certain "telnr".
            I basically just want the "KundID" of the "Kund" I just entered*/
        String getID = "SELECT TOP 1 KundID FROM Kunder WHERE Telnr ='" + kund.telnr + "' ORDER BY KundID DESC";
        ResultSet idSet= sqlHanteraren.select(getID);
        while( idSet.next()) 
            int kundid = idSet.getInt("KundID"); //im getting the ".class expected error" here
        
        return kundid;   
    }
 
 
    
    
}
And here is the code of my SQLHanterare:
import java.sql.*;

public class SQLHanterare {

   String dsn = "xxx";
   String pass = "xxx";
   String id = "xxx";

   public void update( String sqlCommand) {

      try {
         Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver");
         Connection connection= DriverManager.getConnection(
               "jdbc:odbc:" + dsn, id, pass); //Pass och userID

         Statement statement= connection.createStatement();
         int tal =  statement.executeUpdate( sqlCommand );


      } catch (Exception e) {
         System.out.println( e);
      }
   }
   
    public ResultSet select( String sqlCommand) {
       ResultSet resultset = null;
       
       try {
         Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver");
         Connection connection= DriverManager.getConnection(
               "jdbc:odbc:" +dsn, id, pass); //Pass och userID

         Statement statement= connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
                                                         ResultSet.CONCUR_READ_ONLY);
         resultset=  statement.executeQuery( sqlCommand);

      } catch (Exception e) {
         System.out.println( e);       }
      
      return resultset;
      
   }

}
What am I doing wrong, and is there a better way to do it?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 6 2004
Added on Dec 9 2003
5 comments
192 views