S.O.S SOMEONE PLEASE HELP ME - JDBC PROBLEMS

Hi All,

I've been battling with my code, it gives 100 errors, i don't think it's all about the code because, no matter what i change, i still get the exact same 100 errors.

i have used the connection string

static final String con = "jdbc:oracle:thn:@//chuksnb:1521/javadb

i have also registered the driver like this:

DriverManager.registerDriver (new oracle.jdbc.OracleDriver());

below is the line, which in my opinion; should connect to javadb as user scott and password tiger:

Connection conn = DriverManager.getConnection(conn, "scott", "tiger")

wher chuksnb is the localhost name and javadb the oracle service name.

i have also copied everything from oracle_home/jdbc/lib to my working directoty (contains also, my javacode)

then i set my classpath like this:

set classpath=.;

what i'm i doing wrong...i must say, i'm quite frustrated!

The first line of the error message reads :

jdbcApp.java:1: 'class' or 'interface expected

my first line is import java.sql.*;

[1072 byte] By [sunJavaa] at [2007-10-2 7:57:14]
# 1

> Hi All,

>

> I've been battling with my code, it gives 100 errors,

I'll bet there are more than 100 errors. The compiler gives up after a certain point.

> i don't think it's all about the code because, no

> matter what i change, i still get the exact same 100

> errors.

Make no mistake, it's all about your code. You've made this mess.

> i have used the connection string

>

> static final String con =

> "jdbc:oracle:thn:@//chuksnb:1521/javadb

Wrong. That's "thin", not "thin". But your problems are far more fundamental than that.

> i have also registered the driver like this:

> DriverManager.registerDriver (new

> oracle.jdbc.OracleDriver());

Not the best thing to do. Better to pass in a String that's the class name so you don't hard-wire the driver.

> below is the line, which in my opinion; should

> connect to javadb as user scott and password tiger:

>

> Connection conn = DriverManager.getConnection(conn,

> "scott", "tiger")

Your opinion doesn't explain all your 100 errors. This isn't the problem, either. You can't even compile. Connecting is a runtime behavior. You're not even running yet! How do you know what's correct?

> wher chuksnb is the localhost name and javadb the

> oracle service name.

>

> i have also copied everything from

> oracle_home/jdbc/lib to my working directoty

> (contains also, my javacode)

>

> then i set my classpath like this:

> set classpath=.;

Wrong.

> what i'm i doing wrong...i must say, i'm quite

> frustrated!

>

> The first line of the error message reads :

> jdbcApp.java:1: 'class' or 'interface expected

>

> my first line is import java.sql.*;

So post the rest and we'll get a good laugh finding out what you've missed.

%

duffymoa at 2007-7-16 21:47:37 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2
Sorry - "thin", not "thn". You're missing an "i".%
duffymoa at 2007-7-16 21:47:37 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3
the complete error message from the first line is:jdbcApp.java:1 'class' or 'interface' expected{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fontbl{\f0\fnil\fcharset0 Courier New;}{\f1\fswiss\Arial:}}
sunJavaa at 2007-7-16 21:47:37 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 4

> The first line of the error message reads :

> jdbcApp.java:1: 'class' or 'interface expected

This java compiler error indicates that your code is not a correct class definition; it has nothing to do with JDBC, and everything to do with the basics of Java.

There's lots of good Java tutorials on the net, as well as plenty of examples. For Oracle, there are complete working example programs on their web site.

See:

http://www.java2s.com/Code/Java/Database-SQL-JDBC/JDBCSimpleConnection.htm

http://www.oracle.com/technology/sample_code/tech/java/sqlj_jdbc/index.html

StuDerbya at 2007-7-16 21:47:37 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 5

> the complete error message from the first line is:

> jdbcApp.java:1 'class' or 'interface' expected

> {\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fontbl{\f0\

> fnil\fcharset0 Courier New;}{\f1\fswiss\Arial:}}

Yes, that was clear enough the first time.

StuDerby has it right: your .java file isn't considered a legal class by the compiler. Fix that first, then we'll talk about your JDBC problems.

Try posting your entire source. Use code tags, please.

%

duffymoa at 2007-7-16 21:47:37 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 6
So post the rest and we'll get a good laugh finding out what you've missed.I do not think learning should be used as platform for ridicule. To everyone who has posted a more polite response, a big thank you. my program is up and running at last.
sunJavaa at 2007-7-16 21:47:37 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 7
it's not a matter of ridicule. you had compilation problem, not jdbc issues. you should be able to sort those out yourself.%
duffymoa at 2007-7-16 21:47:37 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 8
"i don't think it's all about the code because, no matter what i change,"When I read things like this, it sounds like someone is putting the blame for their problems somewhere besides their code. I think that's counterproductive. And arrogant.%
duffymoa at 2007-7-16 21:47:37 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 9
The problem is that you're using WordPad (probably) to write your Java source code. Use Notepad and you'll find the number of errors drops dramatically.Dave.
dcmintera at 2007-7-16 21:47:37 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 10

> The problem is that you're using WordPad (probably)

> to write your Java source code. Use Notepad and

> you'll find the number of errors drops dramatically.

Wow. Now I see his problem. That's funny, and also a very understandable mistake for a beginning programmer to make.

What he's pointing out is that the .java file has to be in a plain-text file format, not a Rich-text or other "fancy" format. Wordpad (and many other editors) will let you do it either way but by default will try to use Rich-text, which adds a lot of formatting text that java doesn't understand.

StuDerbya at 2007-7-16 21:47:37 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...