Java and Databases help

Soldato
Joined
5 Dec 2003
Posts
2,716
Location
Glasgow
Hey I am trying to follow this tutorial here http://wiki.netbeans.org/AccessMssql to connect to a MS Access database with NetBeans but the code is not working, giving me a number of errors on compile that I don't have a great understanding of:

Code:
52: statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);

Error: incompatible types, found: java.sql.Statement, required: java.beans.Statement

55: resultSet = statement.executeQuery(query);

63: options[i] = new Option(resultSet.getString("NAME"), resultSet.getString("NAME"));

These are the lines giving errors, the last two are cannot find symbol.

Can anyone advise me how to do this successfully in the latest NetBeans?
 
It seems like the .createStatement call is returning a different type to what you've declared statement to be.

Have you imported java.sql.Statement as opposed to java.beans.Statement, at the top of the file ?
 
Lines 55 and 63 are possibly a knock-on problem from the fact that statement cant declare/initialise. The problem with assigning statement to connection.createStatement seems to be that your imports at the top will say something like import java.beans.Statement when it should be java.sql.Statement (or vice versa). Check that your import of statement is for the correct type, then your code should compile.

Edit: pffftt aftershxck :P
 
Thanks, line 63 is still throwing up an error though:

cannot find symbol
constructor Option(java.lang.String, java.lang.String)
location class javax.swing.text.html.Option
 
Well again it seems like the import is potentially wrong for that type, did you follow point 7:

7. Press Ctrl+Shift+I in order to Fix Imports.

Whilst this might magically fix your problem these kind of IDEs take away from the learning process somewhat IMO - maybe learning a bit more about packages and imports/other java fundamentals before attempting that tutorial may be a wise option !
 
Yeah it says nothing to fix in imports.

I did know all this stuff but was about a year ago since I've looked at it, hoped I could follow this guide and get up to speed quick just to do a small project.

I have the "import javax.swing.text.html.Option;" in this time though.
 
OK from looking at that tutorial again I don't think you want:

import javax.swing.text.html.Option;

listBox1.setItems(...) suggests it just wants an array of some 'option' object which contains 2 strings which I assume contains the title/data that wants to be displayed in MS access. I haven't done java for ages though so I'm not sure what 'Option' object you should be using exactly or what type the setItems(..) method actually wants, sorry :o

I'm sure someone else here will have a better idea :p
 
It's complaining that the Option class has no constructor that has a signature that accepts two strings:

http://java.sun.com/javase/6/docs/api/javax/swing/text/html/Option.html

You can see that on the API - so the "Option" class in case here is not javax.swing.text.html.Option.

Only problem is that there doesn't appear to be any other "Option" class in the standard API, perhaps it is included in a jar that you are supposed to have referenced for the tutorial?

Edit: Without reading the whole tutorial (which would prolly be the smart thing to do) it seems that the Option class is actually supposed to be made by your self, it is reading off certain fields of the result set into it which says to me that it is some kind of Value Bean (entity class, model, whatever you wanna call it).
 
Last edited:
Back
Top Bottom