Results 1 to 4 of 4
  1. #1
    new_Java is offline Member
    Join Date
    Feb 2011
    Posts
    5
    Rep Power
    0

    Default Cannot find symbol Error

    Hi All,
    This is my first post on this forum and I have some knowledge of Java..but not enough to run this program successfully.
    I am new to DB connections through JDBC and I am trying to run a very simple query on DB once the conenction is estabilished.But before that, I wanted to test if the connection is established. I have done this in the past
    by giving all the methods in the same file. It worksfine. Now, I want to modify my app into OO style.
    However, I am getting this error as : cannot find symbol
    I feel that there is issue with my contructor with which I am trying to create an obj instance. Please help me.
    Here's the code I have:
    =========================Main Class=========
    import java.sql.*;
    import java.io.*;
    import java.lang.*;

    public class SourceQA{

    public static void main (String[] args) {


    try {
    String dbserver = args[0];
    String propname = args[1];

    GetCon con = new GetCon ();
    Connection connec = con.getConnection(getUrl(propname, dbserver), "blah", "blah");
    /*String sourceVal = source_value(con);*/
    System.out.println("SQL Connection");

    }

    catch (Exception e){
    e.printStackTrace();

    }
    }

    }
    ==============GetCon Class============
    import java.sql.*;
    import java.io.*;
    import java.lang.*;

    public class GetCon {

    public GetCon() {
    Connection con = null;

    }

    //////////Get connection from DB////////
    public static Connection getConnection(String url) throws Exception {
    return getConnection(url, "bla", "bla");
    }

    public static Connection getConnection(String url, String user, String password) throws Exception {
    Connection con = null;
    try{
    //sun.jdbc.odbc.JdbcOdbcDriver
    Class.forName("com.microsoft.sqlserver.jdbc.SQLSer verDriver");
    java.sql.DriverManager.setLoginTimeout(5);
    con = java.sql.DriverManager.getConnection(url,user,pass word);
    } catch(Exception e) {
    e.printStackTrace();
    java.sql.DriverManager.setLoginTimeout(5);
    System.out.println(url);
    con = java.sql.DriverManager.getConnection(url, "DBADMIN", "DBADMIN");
    //throw e;
    }
    return con;
    }

    public static String getUrl(String propname,String dbserver) throws Exception {
    String url = "jdbc:sqlserver://"+dbserver+":1433;databaseName="+propname+";select Method=cursor";
    return url;
    }



    }
    ===================
    javac SourceQA.java
    SourceQA.java:15: cannot find symbol
    symbol : method getUrl(java.lang.String,java.lang.String)
    location: class SourceQA
    Connection connec = con.getConnection(getUrl(dbname, dbserver), "DBADMIN", "
    DBADMIN");
    ^
    1 error

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default

    Since you are not calling teh getUrl method on an object instance the compiler assumes that the method is in the SourceQA class but it isn't. Where is that method?

  3. #3
    new_Java is offline Member
    Join Date
    Feb 2011
    Posts
    5
    Rep Power
    0

    Default Thank You

    Thank you soooo much. I corrected that. It is in the getCon class.sinceI was calling the method getConnection() , I thought, it would know looking at it..got it now.. let me work further on this..it should be con.getUrl()
    Thanks a lot.

  4. #4
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default

    Cheers!

    blah blah blah to make message length long enough. grrrrr

Similar Threads

  1. Cannot find symbol error
    By rajivjoshi in forum New To Java
    Replies: 3
    Last Post: 05-31-2010, 11:13 AM
  2. error cannot find symbol
    By jcoon3 in forum New To Java
    Replies: 3
    Last Post: 09-27-2009, 11:56 PM
  3. Replies: 9
    Last Post: 10-18-2008, 09:26 PM
  4. 'Cannot find symbol' error
    By minihazard10 in forum New To Java
    Replies: 6
    Last Post: 10-10-2008, 05:05 AM
  5. Error: cannot find symbol
    By cachi in forum AWT / Swing
    Replies: 1
    Last Post: 08-06-2007, 09:12 PM

Posting Permissions

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