This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How do I retreive my data from a database

 
Chase Becicka
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic