Results 1 to 4 of 4
Thread: Cannot find symbol Error
- 02-17-2011, 10:31 PM #1
Member
- Join Date
- Feb 2011
- Posts
- 5
- Rep Power
- 0
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
- 02-17-2011, 11:08 PM #2
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?
- 02-17-2011, 11:20 PM #3
Member
- Join Date
- Feb 2011
- Posts
- 5
- Rep Power
- 0
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.
- 02-17-2011, 11:23 PM #4
Similar Threads
-
Cannot find symbol error
By rajivjoshi in forum New To JavaReplies: 3Last Post: 05-31-2010, 10:13 AM -
error cannot find symbol
By jcoon3 in forum New To JavaReplies: 3Last Post: 09-27-2009, 10:56 PM -
cannot find symbol symbol :constructor Error. Please help! =(
By KalEl in forum New To JavaReplies: 9Last Post: 10-18-2008, 08:26 PM -
'Cannot find symbol' error
By minihazard10 in forum New To JavaReplies: 6Last Post: 10-10-2008, 04:05 AM -
Error: cannot find symbol
By cachi in forum AWT / SwingReplies: 1Last Post: 08-06-2007, 08:12 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks