• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Get records using DBUtils

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
insufficient detail to answer to your question.TellTheDetails

welcome to javaranch
 
shan siri
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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("jdbc:odbc: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
 
Sheriff
Posts: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
org.apache.commons.dbutils
 
Rob Spoor
Sheriff
Posts: 22784
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
If you live in a cold climate and on the grid, incandescent light can use less energy than LED. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic