Results 1 to 2 of 2
  1. #1
    ScottThornley is offline Member
    Join Date
    Apr 2010
    Posts
    2
    Rep Power
    0

    Default String.contains works in jdk 6, not in 1.4.2

    The below snippet (swiped from Programming tutorials and source code examples) compiles and runs in jdk 6, but throws an exception in jdk 1.4.2 ( I have to make a jre 1.5 compatible executable, and only have access to the two different jdk's at present)

    Java Code:
          
    .
    .
    .
    
          Class.forName ("oracle.jdbc.OracleDriver");
    	 
          // Enable logging
          // DriverManager.setLogStream(System.err);
    
          System.out.println("Getting Connection");
          Connection conn = DriverManager.getConnection (
          "jdbc:oracle:thin:@192.168.0.77:1521:dbname", "user", "passwd");
    
          // Any warnings generated by the connect?
          checkForWarning(conn.getWarnings());
    
          System.out.println("Creating Statement");
          Statement stmt = conn.createStatement();
    
    
          ResultSet rs = stmt.executeQuery("SELECT * FROM TABLE_NAME");
    
          System.out.println("Retrieving Results");
          int i = 0;
          while (rs.next()) {
    
            System.out.println("Retrieving ID");
            int iID = rs.getInt("ID");
            System.out.println("Retrieving Name");
            String sName = rs.getString("NAME");
            if (sName.contains("XXXXX")){
            	System.out.println("Found XXXXX");
            }
    		System.out.println(sName);
                    //System.out.println("ROW " + ++i + ": " + iID + "; " + sName + "; " + ".");
    }
    .
    .
    .
    The error is:

    Java Code:
    DBConnectionTest.java:58: cannot resolve symbol
    symbol  : method contains (java.lang.String)
    location: class java.lang.String
            if (sName.contains("XXXXX")){
    For the life of me, I cannot see any difference in the String.contains and ResultSet.GetString methods in 1.4.2 and 6 API docs, so I'm just giving up on RTFM and STFW and am going to break down and ask just what the heck I'm doing wrong?

    Again, the code compiles and runs in java 6, but chokes in 1.4.2. The two different jdks are on two different systems. jdk 6 is on a Windows XP workstation, and the 1.4.2 jdk is on a Linux server.

    Thanks,
    Scott
    Last edited by ScottThornley; 04-16-2010 at 10:54 AM. Reason: completeness

  2. #2
    iluxa is offline Senior Member
    Join Date
    Mar 2010
    Posts
    266
    Rep Power
    5

    Default

    Actually, String.contains() method was introduce in 1.5.

    Try instead using

    if (str.indexOf ("XXXXX") >= 0) {
    }

    which should work everywhere

Similar Threads

  1. one works, mine doesn't
    By psychop in forum Java Applets
    Replies: 0
    Last Post: 01-25-2010, 11:36 PM
  2. Custom renderer (almost works)
    By geforce2000 in forum AWT / Swing
    Replies: 11
    Last Post: 12-13-2009, 09:15 PM
  3. Anyone know how GroupLayout works?
    By ProgrammingPup in forum Advanced Java
    Replies: 5
    Last Post: 12-01-2009, 11:12 PM
  4. Javascript works in firefox not IE
    By bghwebmaster in forum Advanced Java
    Replies: 5
    Last Post: 09-29-2009, 01:15 PM
  5. sound works then stops!
    By smileii in forum CLDC and MIDP
    Replies: 0
    Last Post: 09-26-2009, 12:06 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •