| CARVIEW |
Select Language
HTTP/2 302
server: nginx
date: Sun, 18 Jan 2026 04:34:46 GMT
content-type: text/plain; charset=utf-8
content-length: 0
x-archive-redirect-reason: found capture at 20070623232111
location: https://web.archive.org/web/20070623232111/https://qmapper.dev.java.net/
server-timing: captures_list;dur=1.550691, exclusion.robots;dur=0.099278, exclusion.robots.policy;dur=0.082297, esindex;dur=0.031909, cdx.remote;dur=25.810623, LoadShardBlock;dur=273.583828, PetaboxLoader3.datanode;dur=187.158408, PetaboxLoader3.resolve;dur=35.202724
x-app-server: wwwb-app28-dc8
x-ts: 302
x-tr: 353
server-timing: TR;dur=0,Tw;dur=0,Tc;dur=0
set-cookie: wb-p-SERVER=wwwb-app28; path=/
x-location: All
x-as: 14061
x-rl: 0
x-na: 0
x-page-cache: MISS
server-timing: MISS
x-nid: DigitalOcean
referrer-policy: no-referrer-when-downgrade
permissions-policy: interest-cohort=()
HTTP/2 200
server: nginx
date: Sun, 18 Jan 2026 04:34:46 GMT
content-type: text/html;charset=UTF-8
x-archive-orig-date: Sat, 23 Jun 2007 23:21:14 GMT
x-archive-orig-server: Apache
x-archive-orig-x-powered-by: Servlet 2.4; JBoss-4.0.4.GA (build: CVSTag=JBoss_4_0_4_GA date=200605151000)/Tomcat-5.5
x-archive-orig-pragma:
x-archive-orig-cache-control: private,max-age=0,must-revalidate
x-archive-orig-helmloginid: guest
x-archive-orig-connection: close
x-archive-guessed-content-type: text/html
x-archive-guessed-charset: utf-8
memento-datetime: Sat, 23 Jun 2007 23:21:11 GMT
link: ; rel="original", ; rel="timemap"; type="application/link-format", ; rel="timegate"
content-security-policy: default-src 'self' 'unsafe-eval' 'unsafe-inline' data: blob: archive.org web.archive.org web-static.archive.org wayback-api.archive.org athena.archive.org analytics.archive.org pragma.archivelab.org wwwb-events.archive.org
x-archive-src: IA-AROUND-THE-WORLD-2007-20070623221107-12290-crawling021-c/IA-AROUND-THE-WORLD-2007-20070623231813-12957-crawling01.us.archive.org.arc.gz
server-timing: captures_list;dur=0.933416, exclusion.robots;dur=0.041360, exclusion.robots.policy;dur=0.025274, esindex;dur=0.014690, cdx.remote;dur=9.366006, LoadShardBlock;dur=409.809929, PetaboxLoader3.resolve;dur=186.183155, PetaboxLoader3.datanode;dur=193.585035, load_resource;dur=91.967857
x-app-server: wwwb-app28-dc8
x-ts: 200
x-tr: 598
server-timing: TR;dur=0,Tw;dur=0,Tc;dur=0
x-location: All
x-as: 14061
x-rl: 0
x-na: 0
x-page-cache: MISS
server-timing: MISS
x-nid: DigitalOcean
referrer-policy: no-referrer-when-downgrade
permissions-policy: interest-cohort=()
content-encoding: gzip
qmapper: Home
|
qmapper
|
| Summary | externalize complex sql / jdbc code out of your java file! |
|---|---|
| Categories | None |
| License | GNU General Public License (GPL) |
| Owner(s) | livejavabean |
God must have smacked to the back of my brain. Rooted from playing with the reflection API, I accidentally discovered a simple way to solve this headache at work:
a) make query resultset maps to a bean structure.
b) passing the name of the query to a generic querier
to run the query, and return the data back to the
bean structure.
Rather than writing this:
Now I just need to have this in my java code:
Connection con = null; ResultSet rs= null; PreparedStatment stmt= null; try { con = new Connection(url,driver,username,password); String sql = "SELECT a.id,a.subject,a.message,a.creationDate,b.username" + "FROM blogs as a, user_profiles as b "+ "WHERE a.user_id=b.user_id AND b.username=?"; stmt = con.prepareStatment(sql); stmt.setParam(1, pUsername); rs = stmt.execute(); ArrayList blogs = new ArrayList(); While (rs.next()) { Blog blog = new Blog(); blog.setId(rs.getInt(1)); blog.setSubject(rs.getString(2)); blog.setMessage(rs.getString(3)); blog.setCreationDate(rs.getDate(4)); User user = new User(); user.setUsername(rs.getString(5)); blog.setAuthor(user); blogs.add(blog); } return blogs; } catch (Exception e) { e.printStackTrace(); return null; } finally { try { if (con != null) con.close(); } catch (Exception ignored) {} try { if (stmt != null) stmt.close();} catch (Exception ignored) {} try { if (rs != null) rs.close(); } catch (Exception ignored) {} }
QueryManager manager = new QueryManager("D:/xmlconfig.xml");
ArrayList params = new ArrayList();
params.add("livejavabean");
ArrayList blogs = (ArrayList)manager.executeQuery("get_user_blogs",params);
for(int i=0; i<blogs.size(); i++) {
Blog blog = (Blog) blogs.get(i);
System.out.println(blog.getId());
System.out.println(blog.getAuthor().getUsername());
System.out.println(blog.getAuthor().getName().getFirstName());
System.out.println(blog.getAuthor().getName().getLastName());
}
And in the xml config, I simply defined the jdbc connection,
the query, and how the resultset should be mapped to the bean... hey it will
create instance for any member bean also!...
<?xml version="1.0"
<encoding="UTF-8"?>
<bean-query>
<connections>
<connection name="ljb">
<url>jdbc:mysql://localhost/livejavabean</url>
<driver>org.gjt.mm.mysql.Driver</driver>
<username></username>
<password></password>
</connection>
</connections>
<queries>
<query name="get_user_blogs" connection="ljb" cache="true" preload="false">
<sql><![CDATA[
SELECT
a.id,
a.subject,
a.message,
a.creationDate,
b.username,
b.firstName,
b.lastName
b.email,
FROM
blogs as a,
user_profiles as b
WHERE
a.user_id=b.user_id AND
b.username=?";
]]></sql>
<bean-mapping class="org.sifut.blog.Blog" return-as-list="false">
<property>id</property>
<property>subject</property>
<property>message</property>
<property>creationDate</property>
<property>author.username</property>
<property>author.name.firstName</property>
<property>author.name.lastName</property>
<property>author.email</property>
</bean-mapping>
</query>
</queries>
</bean-query>
| Powered by CollabNet | Feedback |
FAQ |
Press |
Developer tools
© 1995 - 2007 CollabNet. CollabNet is a registered trademark of CollabNet, Inc. |
