This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes Get records using DBUtils Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Get records using DBUtils" Watch "Get records using DBUtils" New topic
Author

Get records using DBUtils

shan siri
Greenhorn

Joined: Jun 14, 2010
Posts: 7

Hi,


I am new to DBUtils database programming.I can access to the database but i unable to print record. I am getting output null values.

ID null
Name null
description null


Why i am getting all null values. Could you please help me...

Code:


ResultSetHandler h = new BeanHandler(GetDataBean.class);

GetDataBean records = (GetDataBean) run.query(con1,"SELECT id, name, desc FROM tblStudent where id ='1234' ", h);

System.out.println("ID"+ records.getId());
System.out.println("Name"+records.getName());
System.out.println("Description"+ records.getDesc());


Thanks
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

insufficient detail to answer to your question.TellTheDetails

welcome to javaranch
shan siri
Greenhorn

Joined: Jun 14, 2010
Posts: 7
Hi ,

I am trying to access MSAccess database. Here is full code.

try {

QueryRunner run = new QueryRunner();
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver") ;
Connection con1 = DriverManager.getConnection("jdbcdbc:studentData");
System.out.println("Connection ok.");
ResultSetHandler h = new BeanHandler(GetDataBean.class);
GetDataBean records = (GetDataBean) run.query(con1,"SELECT id, name, desc FROM tblStudent where id ='1234' ", h);
System.out.println("ID"+ records.getId());
System.out.println("Name"+records.getName());
System.out.println("Description"+ records.getDesc());
} catch (SQLException sqle) {
log.error("could not read a value", sqle);

} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


Thanks
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

Do you have any idea how many classes there are called DBUtils? Should we just guess that you mean the Apache Commons DbUtils one?

Do you have methods setId, setName and setDesc that take Strings, or whatever the columns in your query are?


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
shan siri
Greenhorn

Joined: Jun 14, 2010
Posts: 7
org.apache.commons.dbutils
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

I already guessed that much. Can you now please answer my second question? Perhaps you can show us the GetDataBean class.
shan siri
Greenhorn

Joined: Jun 14, 2010
Posts: 7
I am getting record when i use commons-dbutils1.0.jar .But when i am trying to use 1.3 version i am not getting any records. But i need to use 1.3 version.Because the below update function exists only in 1.3 version.

How can i do it? Could you please help me.

int inserts = run.update(con1,"INSERT INTO tblBachelor (id, name, desc) VALUES (?,?,?)", records.getId(), records.getName(), records.getDesc());





Bean Code :


public class GetDataBean

private String id;
private String name;
private String desc;

public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

Thanks

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Get records using DBUtils
 
Similar Threads
Value is session managed bean's attribute is nulled
ORA-01460: unimplemented or unreasonable conversion requested
SQL Error :java.sql.SQLException: No suitable driver
Problem with c:foreach not working
cant able to send values with % symbol between JSP pages.