|
From: <tri...@tr...> - 2004-02-16 21:20:03
|
I have committed the new method to CVS. I will add my local tests to the proper
test class later today or tomorrow (this is a standalone feature so little risk
of breaking any other functionality). This might actually turn out to be more
of a test of MockObjects than real code, but it will at least outline expected
functionality.
I ended up implementing (3) as an ArrayList of HashMaps using the column name as
key. We could replace this with a disconnected rowset in the future.
I'll think about the convenience method - is "int" sufficient?
Here is an example:
DriverManagerDataSource ds = new DriverManagerDataSource();
ds.setDriverClassName("oracle.jdbc.driver.OracleDriver");
ds.setUrl("jdbc:oracle:thin:@localhost:1521:ORCL");
ds.setUsername("scott");
ds.setPassword("tiger");
JdbcTemplate jt = new JdbcTemplate(ds);
Object o = jt.runSqlStatement("select * from emp");
System.out.println(o.getClass().getName());
System.out.println(o);
java.util.ArrayList
[{SAL=800, HIREDATE=1980-12-17 00:00:00.0, COMM=null, EMPNO=7369, JOB=CLERK,
DEPTNO=20, MGR=7902, ENAME=SMITH}, {SAL=1600, HIREDATE=1981-02-20 00:00:00.0,
COMM=300, EMPNO=7499, JOB=SALESMAN, DEPTNO=30, MGR=7698, ENAME=ALLEN},
{SAL=1250, HIREDATE=1981-02-22 00:00:00.0, COMM=500, EMPNO=7521, JOB=SALESMAN,
DEPTNO=30, MGR=7698, ENAME=WARD}, {SAL=2975, HIREDATE=1981-04-02 00:00:00.0,
COMM=null, EMPNO=7566, JOB=MANAGER, DEPTNO=20, MGR=7839, ENAME=JONES},
{SAL=1250, HIREDATE=1981-09-28 00:00:00.0, COMM=1400, EMPNO=7654, JOB=SALESMAN,
DEPTNO=30, MGR=7698, ENAME=MARTIN}, {SAL=2850, HIREDATE=1981-05-01 00:00:00.0,
COMM=null, EMPNO=7698, JOB=MANAGER, DEPTNO=30, MGR=7839, ENAME=BLAKE},
{SAL=2450, HIREDATE=1981-06-09 00:00:00.0, COMM=null, EMPNO=7782, JOB=MANAGER,
DEPTNO=10, MGR=7839, ENAME=CLARK}, {SAL=3000, HIREDATE=1987-04-19 00:00:00.0,
COMM=null, EMPNO=7788, JOB=ANALYST, DEPTNO=20, MGR=7566, ENAME=SCOTT},
{SAL=5000, HIREDATE=1981-11-17 00:00:00.0, COMM=null, EMPNO=7839, JOB=PRESIDENT,
DEPTNO=10, MGR=null, ENAME=KING}, {SAL=1500, HIREDATE=1981-09-08 00:00:00.0,
COMM=0, EMPNO=7844, JOB=SALESMAN, DEPTNO=30, MGR=7698, ENAME=TURNER}, {SAL=1100,
HIREDATE=1987-05-23 00:00:00.0, COMM=null, EMPNO=7876, JOB=CLERK, DEPTNO=20,
MGR=7788, ENAME=ADAMS}, {SAL=950, HIREDATE=1981-12-03 00:00:00.0, COMM=null,
EMPNO=7900, JOB=CLERK, DEPTNO=30, MGR=7698, ENAME=JAMES}, {SAL=3000,
HIREDATE=1981-12-03 00:00:00.0, COMM=null, EMPNO=7902, JOB=ANALYST, DEPTNO=20,
MGR=7566, ENAME=FORD}, {SAL=1300, HIREDATE=1982-01-23 00:00:00.0, COMM=null,
EMPNO=7934, JOB=CLERK, DEPTNO=10, MGR=7782, ENAME=MILLER}]
Thomas
Quoting Rod Johnson <rod...@in...>:
> Thomas,
>
> Sounds great. With this there I'd be glad to get rid of JdbcHelper.
>
> Not sure about (3). I think this needs further thought. For 1.1 we could add
> a true disconnected result set: not RowSet as it throws SQLException, which
> we want to get away from.
>
> Also a convenience method returning int would be handy, for counts and the
> like. Please can I have this, despite Juergen's dislike of convenience
> methods :-)
>
> Regards,
> Rod
>
> ----- Original Message -----
> From: <tri...@tr...>
> To: <spr...@li...>
> Sent: Monday, February 16, 2004 5:26 PM
> Subject: RE: [Springframework-developer] JdbcHelper
>
>
> > I can see the need to go beyond a single row/value type query.
> >
> > How about a new method for the JdbcTemplate:
> >
> > Object runSqlStatement(String)
> >
> > Based on the type of SQL passed in it would return:
> >
> > 1) An Integer containing the number of rows affected if it is an update
> statement
> >
> > runSqlStatement("update emp set salary = salary * 1.5") would return an
> Integer
> > with the update count
> >
> > 2) A single Object (Integer/Long/String) based on the value returned from
> a
> > single value/single row query
> >
> > runSqlStatement("select last_name frmo emp where id = 2") would return a
> String
> > containing the last name
> >
> > 3) An ArrayList of ArrayLists containing a list of rows with a list of
> column
> > values returned by the query
> >
> > runSqlStatement("selecy id, last_name from emp") would return an ArrayList
> > containing an ArrayList for each row. The second list would contain an
> Integer
> > with the id and a String with the last_name.
> >
> >
> > Number 3 might be a stretch, but we would still have to check for this,
> since we
> > have no control over the SQL coming in.
> >
> > Thomas
> >
> >
> > Quoting rod...@in...:
> >
> > > I've actually just (yesterday) introduced into into a whole
> > > bunch of test cases at a client. Maybe we could put an
> > > improved runSQLFunction() method on JdbcTemplate? This is a
> > > very convenient one-liner, and basically the only reason I
> > > use JdbcTemplate.
> > >
> > > Regards,
> > > Rod
> > >
> > >
> > > -------------------------------------------------------
> > > SF.Net is sponsored by: Speed Start Your Linux Apps Now.
> > > Build and deploy apps & Web services for Linux with
> > > a free DVD software kit from IBM. Click Now!
> > > http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
> > > _______________________________________________
> > > Springframework-developer mailing list
> > > Spr...@li...
> > > https://lists.sourceforge.net/lists/listinfo/springframework-developer
> > >
> >
> >
> >
> >
> >
> > -------------------------------------------------------
> > SF.Net is sponsored by: Speed Start Your Linux Apps Now.
> > Build and deploy apps & Web services for Linux with
> > a free DVD software kit from IBM. Click Now!
> > http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
> > _______________________________________________
> > Springframework-developer mailing list
> > Spr...@li...
> > https://lists.sourceforge.net/lists/listinfo/springframework-developer
>
>
>
>
> -------------------------------------------------------
> SF.Net is sponsored by: Speed Start Your Linux Apps Now.
> Build and deploy apps & Web services for Linux with
> a free DVD software kit from IBM. Click Now!
> http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
> _______________________________________________
> Springframework-developer mailing list
> Spr...@li...
> https://lists.sourceforge.net/lists/listinfo/springframework-developer
>
|