Results 1 to 6 of 6
  1. #1
    MagicMichael is offline Member
    Join Date
    Jan 2011
    Posts
    3
    Rep Power
    0

    Default Don't see the error

    I must be blind, but I don't see why I'm having a problem with this code:

    package com.weblore.sym;
    import java.util.*;
    import java.sql.*;
    public class SymDatabase {
    Connection cn;
    Properties props = new Properties();
    props.setProperty("user", "michael2");

    -- - - - - - - - - - - -

    Obviously, there is code that follows, but it's the last line that shows the error. When I try to compile it, I get:

    SymDatabase.java:9: <identifier> expected
    p.setProperty("user", "michael2");
    ^
    SymDatabase.java:9: illegal start of type
    p.setProperty("user", "michael2");
    ^
    SymDatabase.java:9: illegal start of type
    p.setProperty("user", "michael2");

    I'd really appreciate it if someone could point out what I'm missing.
    Thanks much.

  2. #2
    aspire1 is offline Member
    Join Date
    Jan 2011
    Posts
    13
    Rep Power
    0

    Default

    Where did you declare p ? all I can see is props.

  3. #3
    goldest's Avatar
    goldest is offline Senior Member
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    469
    Rep Power
    5

    Wink

    Quote Originally Posted by MagicMichael View Post
    Obviously, there is code that follows
    And where is that?
    Java Is A Funny Language... Really!
    Click on * and add to member reputation, if you find their advices/solutions effective.

  4. #4
    MagicMichael is offline Member
    Join Date
    Jan 2011
    Posts
    3
    Rep Power
    0

    Default

    Quote Originally Posted by aspire1 View Post
    Where did you declare p ? all I can see is props.
    I'm an idiot (actually, I have the flu and am not completely here) - but not for omitting the declaration. FOR THE POST, I changed p to props - and didn't complete the change. Her is the code verbatim with no patches:

    package com.weblore.sym;
    import java.util.*;
    import java.sql.*;
    public class SymDatabase {
    Connection cn;
    Properties p = new Properties();
    p.setProperty("user", "michael2");

    Please forgive me for the stupid first pass
    ---Michael

  5. #5
    aspire1 is offline Member
    Join Date
    Jan 2011
    Posts
    13
    Rep Power
    0

    Default

    Well in that case, p.setProperty("user", "michael2") is just dangling there in the middle of nowhere, has to be put in the constructor or some other method that's part of the class.

  6. #6
    MagicMichael is offline Member
    Join Date
    Jan 2011
    Posts
    3
    Rep Power
    0

    Default

    Quote Originally Posted by aspire1 View Post
    Well in that case, p.setProperty("user", "michael2") is just dangling there in the middle of nowhere, has to be put in the constructor or some other method that's part of the class.
    You are absolutely correct. I sincerely apologize. I think I need to stop writing code until I lose this fever.

    Thanks for the help. I do feel like an idiot.

Similar Threads

  1. java out of memory error-heap space error
    By elsanthosh in forum NetBeans
    Replies: 4
    Last Post: 06-15-2010, 09:31 AM
  2. Replies: 1
    Last Post: 03-10-2010, 01:53 PM
  3. Replies: 1
    Last Post: 12-05-2009, 07:28 AM
  4. Replies: 1
    Last Post: 10-26-2009, 04:38 PM
  5. Replies: 3
    Last Post: 01-23-2009, 08:53 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
  •