Dear Mr. Graham:
I have good and bad news: In my code I
did this:
BasicRowProcessor rowProcessor = new
BasicRowProcessor(new
BasicColumnProcessor());
lista = rowProcessor.toBeanList(rs,
CLASS);
Well, int attributes are showed
correctly, but a char attribute
(called codTipoAutor) not; and this
value is not null in dadtabase.
Other thing: When I created
rowProcessor I needed explicity use
BasicColumnProcessor in constructor.
If I use default constructor,
primitive attributes are showed with 0
values.
Below the printed results:
Calling findAllByBasicRowProcessor() ...
Showing Ocorrencia.getCodigo() ...
5 - 6 - 9 - 10 - 11 - 19 - 13 - 14 -
15 - 17 -
Showing Ocorrencia.getObservacao() ...
alfa
bweta - qwdeqweqweqw - birita -
vitasmina - uga buga - 797987
464343 - qweqweqwe - observa��es -
3r2aerwer - dfhettrttrtttr -
Showing Ocorrencia.getDataOcorrencia() ...
2004-01-27 09:36:00.0 - 2004-01-27
10:20:00.0 - 2004-01-27 10:40:00.0 -
2004-01-27 10:54:00.0 - 2004-01-27
12:42:00.0 - 2004-02-01 11:59:00.0 -
2004-01-29 14:21:00.0 - 2004-01-29
14:24:00.0 - 2004-02-03 10:30:00.0 -
2004-02-03 10:30:00.0 -
Showing Ocorrencia.getCodTipoAtor() ...
Calling findAllByRunQuery() ...
[Ocorrencia[codigo=0, codAtor=0,
codTipoAtor=
Observe that codigo attribute (a int)
is correctly showed but codTipoAtor (a
char) not. What can be wrong?
Below I show my classes code:
// Ocorrencia.java
import java.io.Serializable;
import java.sql.Timestamp;
/**
* @author rafael
*
*/
public class Ocorrencia implements
Serializable {
private int codigo;
private int codAtor;
private char codTipoAtor;
private int codTipo;
private Timestamp dataOcorrencia;
private String observacao;
// Getters and setters
/**
* @return
* @see java.lang.Object#toString()
*/
public String toString() {
StringBuffer sbObject =
new
StringBuffer(this.getClass().getName()
+ "[");
sbObject.append("codigo=").append(this.getCodigo());
sbObject.append(",
codAtor=").append(this.getCodAtor());
sbObject.append(",
codTipoAtor=").append(this.getCodTipoAtor());
sbObject.append(",
tipo=").append(this.getCodTipo());
sbObject.append(",
dataOcorrencia=").append(this.getDataOcorrencia());
sbObject.append(",
observacao=").append(this.getObservacao());
sbObject.append("]");
return sbObject.toString();
}
}
// TestChar.java
import java.sql.*;
import java.util.*;
import org.apache.commons.dbutils.*;
import
org.apache.commons.dbutils.handlers.*;
/**
* @author rafael
*
*/
public class TestChar {
private static final String
DRIVER = "com.mysql.jdbc.Driver";
private static final String URL
= "jdbc:mysql://localhost:3306/order";
private static final String
USER = "root";
private static final String
PASS = "";
private static final String
QUERY = "SELECT * FROM ocorrencia";
private static final Class
CLASS = Ocorrencia.class;
protected List
findAllByBasicRowProcessor() {
List lista =
Collections.EMPTY_LIST;
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
Class.forName(DRIVER).newInstance();
conn =
DriverManager.getConnection(URL, USER,
PASS);
stmt = conn.createStatement();
rs = stmt.executeQuery(QUERY);
BasicRowProcessor
rowProcessor =
new
BasicRowProcessor(new
BasicColumnProcessor());
lista =
rowProcessor.toBeanList(rs, CLASS);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
DbUtils.close(rs);
DbUtils.close(stmt);
DbUtils.close(conn);
} catch (SQLException
sqlEx) {
sqlEx.printStackTrace();
}
}
return lista;
}
protected void findAllByRunQuery() {
Connection conn = null;
try {
Class.forName(DRIVER).newInstance();
conn =
DriverManager.getConnection(URL, USER,
PASS);
QueryRunner run = new
QueryRunner();
BeanListHandler
listHandler = new BeanListHandler(CLASS);
List list = (List)
run.query(conn, QUERY, listHandler);
System.out.println(list);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
DbUtils.close(conn);
} catch (SQLException
sqlEx) {
sqlEx.printStackTrace();
}
}
}
public static void main(String[]
args) throws Exception {
TestChar test = new TestChar();
System.out.println("Calling
findAllByBasicRowProcessor() ...");
List list =
test.findAllByBasicRowProcessor();
System.out.println("Showing
Ocorrencia.getCodigo() ...");
for(int i = 0; i <
list.size(); i ++){
System.out.print(((Ocorrencia)list.get(i)).getCodigo()
+ " - ");
}
System.out.println("\nShowing
Ocorrencia.getObservacao() ...");
for(int i = 0; i <
list.size(); i ++){
System.out.print(((Ocorrencia)list.get(i)).getObservacao()
+ " - ");
}
System.out.println("\nShowing
Ocorrencia.getDataOcorrencia() ...");
for(int i = 0; i <
list.size(); i ++){
System.out.print(((Ocorrencia)list.get(i)).getDataOcorrencia()
+ " - ");
}
System.out.println("\nShowing
Ocorrencia.getCodTipoAtor() ...");
for(int i = 0; i <
list.size(); i ++){
System.out.print(((Ocorrencia)list.get(i)).getCodTipoAtor()
+ " - ");
}
System.out.println("\nShowing
TipoOcorrencia list (it does not work)
...");
System.out.println(list);
System.out.println("Calling
findAllByRunQuery() ...");
test.findAllByRunQuery();
}
}
// ocorrencias.sql
USE order;
#
# Table structure for table 'ocorrencia'
#
DROP TABLE IF EXISTS ocorrencia;
CREATE TABLE ocorrencia (
codigo int(10) unsigned NOT NULL
auto_increment,
codAtor int(10) unsigned NOT NULL
default '0',
codTipoAtor char(1) NOT NULL default '',
codTipo int(10) unsigned NOT NULL
default '0',
dataOcorrencia datetime NOT NULL
default '0000-00-00 00:00:00',
observacao varchar(255) default NULL,
PRIMARY KEY (codigo),
KEY ocorrencia_tipo (codTipo),
KEY ocorrencia_referencia
(codTipoAtor,codAtor,dataOcorrencia,codTipo)
) TYPE=MyISAM;
#
# Dumping data for table 'ocorrencia'
#
INSERT INTO ocorrencia VALUES("5",
"2", "N", "7", "2004-01-27 09:36:00",
"alfa\r\nbweta");
INSERT INTO ocorrencia VALUES("6",
"3", "N", "6", "2004-01-27 10:20:00",
"qwdeqweqweqw");
INSERT INTO ocorrencia VALUES("9",
"3", "N", "7", "2004-01-27 10:40:00",
"birita");
INSERT INTO ocorrencia VALUES("10",
"4", "I", "8", "2004-01-27 10:54:00",
"vitasmina");
INSERT INTO ocorrencia VALUES("11",
"5", "I", "9", "2004-01-27 12:42:00",
"uga buga");
INSERT INTO ocorrencia VALUES("19",
"18", "I", "9", "2004-02-01 11:59:00",
"797987\r\n464343");
INSERT INTO ocorrencia VALUES("13",
"10", "N", "7", "2004-01-29 14:21:00",
"qweqweqwe");
INSERT INTO ocorrencia VALUES("14",
"10", "N", "7", "2004-01-29 14:24:00",
"observa��es");
INSERT INTO ocorrencia VALUES("15",
"19", "I", "8", "2004-02-03 10:30:00",
"3r2aerwer");
INSERT INTO ocorrencia VALUES("17",
"15", "I", "9", "2004-02-03 10:30:00",
"dfhettrttrtttr");
Thanks,
Rafael Ubiratam Clemente Afonso
[EMAIL PROTECTED]
---------------------------------
Where is Debug?
Debug is on the Table!
---
Acabe com aquelas janelinhas que pulam na sua tela.
AntiPop-up UOL - � gr�tis!
http://antipopup.uol.com.br
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]