I am using Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); in one of my programs, but it keeps on coming up with the error "the method forName(String) is not defined for the type Class". What am I doing wrong? The book I am reading doesn't specify that I need to do any special imports. I am importing java.sql.*. Since it throws a class not found exception, I already have it in a try block with a catch (ClassNotFoundException e) block behind it.
Nope, the class I am working with doesn't even have the word "Class" in it.
I created another program using it and it works fine. I even tried copying and pasting the code from one program to another and editing it to fit the needs of the one I am doing now, but that doesn't work. I still get the same error.
Thanks for the replies! I am not sure what the issue is here. I cannot figure this out; it is so weird! And, to make it even stranger, I just re-coded it in a completely different package (I'm using eclipse) and it recognizes Class.forName(String). What is the difference between the two? I am importing java.sql.* at the beginning. I will try the other qualifiers that you have suggested, and I'll let you know tonight!
What do you mean by CLASSPATH? Where can I find those settings?
The CLASSPATH is an environment variable that the java compiler looks at for hints on how to find some classes when it compiles. (Generally, these would be your own, user classes, so this probably isn't your problem). You can specify a different CLASSPATH when you run the compiler, and javac will temporarily use that.
How to set it depends on your platform and what, if any, IDE you're using. Sun has some info on the CLASSPATH, as it pertains to the Windows version of the java SDK.
There are other compiler options that might (just maybe) cause Java to not know what a class is. The "target" and "bootclasspath" options, for example. Still, Class.forName() has been around since 1.0. Hmmmm... I'm just tossing out things here--I'm really not sure what the culprit is.
OK, I tried using java.lang.forName(...) and it worked. So thanks! I also tried the Class.class.forName() and there it was! All ready to work. Man oh man...
Now, I have one more issue and then I will stop bugging everyone for a bit; I promise. I am trying to connect to a db and insert records into it. The insert works, but I also get an exception, saying that "No ResultSet was produced SQL State: null". I have my code in try / catch blocks so it catches the errors. It inserts the record fine, but still gives me the error BEFORE it reports the insert. So, I commented out the code to write the record to the database and I get strange results: every field comes up as null in the console (there are only 6 fields right now). Here is my code:
There is also a Customer class in the same package that has the setFirstName(), setLastName(), setAddress(), etc. methods that it is using. That is also how I am creating a new customer object.
The results, when run WITH the setCustomerInfoToDB, are these:
Exception: No ResultSet was produced SQL State: null Customer from DB: Clark Kent 211 North Metropolis IL 60651
When run WITHOUT the setCustomerInfoToDB (I just commented it out), these are the results: