• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Get records using DBUtils

 
shan siri
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 5575
Eclipse IDE Java Windows XP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
insufficient detail to answer to your question.TellTheDetails

welcome to javaranch
 
shan siri
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20396
47
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
shan siri
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
org.apache.commons.dbutils
 
Rob Spoor
Sheriff
Pie
Posts: 20396
47
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I already guessed that much. Can you now please answer my second question? Perhaps you can show us the GetDataBean class.
 
shan siri
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic