, getString(), Java String. , MySQL Java, getXXX(). init script:
DROP TABLE IF EXISTS thing;
CREATE TABLE thing (
a_int int,
a_string text,
a_date date
);
INSERT INTO thing (a_int, a_string, a_date)
VALUES ('1234', 'Hello world', CURRENT_DATE() );
:
public static void main(String[] args) throws Exception {
MysqlDataSource db = new MysqlDataSource();
db.setDatabaseName("test");
Connection conn = db.getConnection("test", "test");
ResultSet res = conn.prepareStatement("SELECT * FROM thing").executeQuery();
res.next();
System.out.println("Get a int as a string: " + res.getString("a_int"));
}
Get a int as a string: 1234. a_date Java int, 2013 . , , , . , , getInt() TEXT.