Two Laptop Bag*
The moose likes Testing and the fly likes Read data from the database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Read data from the database" Watch "Read data from the database" New topic
Author

Read data from the database

Claudiu Barbulescu
Greenhorn

Joined: Dec 04, 2012
Posts: 13
Hi,

I have the below Selenium RC script. The script will create an user in the site. Then I use JDBC connection to verify in the database to see if the user was successfully added.
The problem is that when read from the database->Users Table in the console are displayed only de ID. I want to display this columns: ID and Email.
So, how to improve the below code to show this columns in Eclipse-Console with inserted data. Please see the attached images.

Thank you!



[users table.jpg]

[Thumbnail for java console output.jpg]

E Armitage
Rancher

Joined: Mar 17, 2012
Posts: 892
    
    9
Do you know what this part of the code is doing?
Claudiu Barbulescu
Greenhorn

Joined: Dec 04, 2012
Posts: 13
E Armitage wrote:Do you know what this part of the code is doing?


No, I don't know exactly what is doing. Can you explain in details? Thanks
E Armitage
Rancher

Joined: Mar 17, 2012
Posts: 892
    
    9
It reads the first column returned in the select and prints it out. You should read a jdbc tutorial first (google it) before writing/modifying code that uses JDBC classes.
Claudiu Barbulescu
Greenhorn

Joined: Dec 04, 2012
Posts: 13
E Armitage wrote:It reads the first column returned in the select and prints it out. You should read a jdbc tutorial first (google it) before writing/modifying code that uses JDBC classes.


OK. Thanks I will read. But how to modify the code to show: first column, 2nd column... with their afferent column name and data, exactly like in MySql?
E Armitage
Rancher

Joined: Mar 17, 2012
Posts: 892
    
    9
Claudiu Barbulescu wrote:
E Armitage wrote:It reads the first column returned in the select and prints it out. You should read a jdbc tutorial first (google it) before writing/modifying code that uses JDBC classes.


OK. Thanks I will read. But how to modify the code to show: first column, 2nd column... with their afferent column name and data, exactly like in MySql?

Without reading about how to do it? If you read my question and reply above closely you would be able to work it out but better is to do the right thing and only modify code that you understand by reading about JDBC first.
Claudiu Barbulescu
Greenhorn

Joined: Dec 04, 2012
Posts: 13
E Armitage wrote:
Claudiu Barbulescu wrote:
E Armitage wrote:It reads the first column returned in the select and prints it out. You should read a jdbc tutorial first (google it) before writing/modifying code that uses JDBC classes.


OK. Thanks I will read. But how to modify the code to show: first column, 2nd column... with their afferent column name and data, exactly like in MySql?

Without reading about how to do it? If you read my question and reply above closely you would be able to work it out but better is to do the right thing and only modify code that you understand by reading about JDBC first.


I think that I found a way to resolve this:
I declared:

I continue to read the full JDBC tutorial to show in the console the name of the columns.Thanks man.
The output in console looks like below:

L.A: I improved the code with this:


Now is more user friendly in the console


[Thumbnail for db.jpg]

[Thumbnail for db1.jpg]

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Read data from the database