jQuery in Action, 2nd edition*
The moose likes Beginning Java and the fly likes How do I retreive my data from a database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How do I retreive my data from a database" Watch "How do I retreive my data from a database" New topic
Author

How do I retreive my data from a database

Chase Becicka
Greenhorn

Joined: Feb 16, 2004
Posts: 23
I'm using a database for the first time and am trying to extract the columns I created I can make the connection but I can't figure out how to get the columns I have out and then get them assigned to appropriate variables any code examples or weblinks would be much appriciated
Landon Blake
Ranch Hand

Joined: Oct 15, 2004
Posts: 44
Chase,

We need a little more details before your question can be answered.

Which database are you using?
Are you connecting to it through another program, like a database GUI or front-end? If so, which one?

Or, are you trying to access the database programatically?

You may want to try the users forum of the database you are using, if there is one. They should be able to tell you how to access the differnt elements of the database you are using. These methods of access change depending on the database you are using.

Landon
Chase Becicka
Greenhorn

Joined: Feb 16, 2004
Posts: 23
I am using SQL Server and I have two tables that I joined with one common named column which is the primary key value on both tables

the code i am using to connect is

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc dbc:javaBank";
String user = "sa";
String password = "";
connection = DriverManager.getConnection(url, user, password);

I have three files going my GUI file my connectDB file which is where I got the code above and I am trying to write a file that gets the info from the connectDB file and gives it to the methods in my inventGUI file put as I said I don't know how to get data from the columns once I connect
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1824

Use the java.sql.Connection you obtained to get a java.sql.Statement (or a java.sql.PreparedStatement). Use these to run SQL Queries, which return a java.sql.ResultSet. Parse the results of the ResultSet, and you've got your data. Check out the links to the JavaDocs, and if you have any further questions, the Ranch (and Google!) is open 24/7.


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How do I retreive my data from a database