cant get Java code to work
Hello
My JDBCDemo class code is
Code:
public class JDBCDemo {
Connection db_connection;
Statement db_statement;
ResultSet result;
}
and it is not importing the required libraries which define Connection, Statement, Resultset.
I guess these are all javaclasses, if they are, is there any way to find which libraries they are located in, so that i may add the required libraries? is there any way i can add the rt.jar to JDBCDemo.java, or is that not possible
i tried to compile JDBCDemo.java and it came up with the following
C:\JDBCApp>javac JDBCDemo.java
JDBCDemo.java:2: cannot resolve symbol
symbol : class Connection
location: class JDBCDemo
Connection db_connection;
^
JDBCDemo.java:3: cannot resolve symbol
symbol : class Statement
location: class JDBCDemo
Statement db_statement;
^
JDBCDemo.java:4: cannot resolve symbol
symbol : class ResultSet
location: class JDBCDemo
ResultSet result;
^
3 errors
C:\JDBCApp>
Re: cant get Java code to work
Have you included
Code:
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;
at the start top of the file?
Re: cant get Java code to work
Quote:
Originally Posted by vb_student
I guess these are all javaclasses,
Obviously ...
Quote:
if they are, is there any way to find which libraries they are located in, so that i may add the required libraries?
Well, how did you learn about them? That tells you in which package they are. Once you know that, you can search for their fully qualified name to find out what they're part of.
Of course, since they're all from java.sql, they're all part of the standard distribution, so there's nothing you need to add.
Quote:
is there any way i can add the rt.jar to JDBCDemo.java, or is that not possible
rt.jar is always in the classpath, unless you override the boot classpath.
Quote:
i tried to compile JDBCDemo.java and it came up with the following
C:\JDBCApp>javac JDBCDemo.java
JDBCDemo.java:2: cannot resolve symbol
symbol : class Connection
location: class JDBCDemo
Connection db_connection;
^
The compiler is looking for a class Connection. This should tell you that something is wrong: you're using JDBC, so it should be looking for java.sql.Connection. In other words, you need to either fully qualify the name (i.e. use java.sql.Connection whereever you use Connection now) or tell the compiler that you really mean java.sql.Connection whenever you say Connection. That's what the import statement is for.
See DeadEyes' post for the actual specific solution to your problem.
Re: cant get Java code to work
thanks for the response dude,
it makes sense