java - Performe nested select statement with Spring JDBC -
i have problem executing nested select statement. here sql :
select count(*) posts p p.id in (select u.postid users u) ;
i'm using mysql , working when try mysql workbench when try in application in i'm using spring jdbc, throws me "org.springframework.jdbc.uncategorizedsqlexception."
here how i'm using in app:
getjdbctemplate().queryforobject(sql, integer.class);
i had tried , :
getjdbctemplate().query(sql, new rowcountcallbackhandler());
both ways not working , error.
is there configuration options or allowed me execute such nested select statements ?
edit
the error trace is:
[3d000]; error code [1046]; no database selected; nested exception java.sql.sqlexception: no data base selected @ org.springframework.jdbc.support.abstractfallbacksqlexceptiontranslator.translate(abstrac tfallbacksqlexceptiontranslator.java:84) @ org.springframework.jdbc.support.abstractfallbacksqlexceptiontranslator.translate(abstrac tfallbacksqlexceptiontranslator.java:81) @ org.springframework.jdbc.support.abstractfallbacksqlexceptiontranslator.translate(abstrac tfallbacksqlexceptiontranslator.java:81) @ org.springframework.jdbc.core.jdbctemplate.execute(jdbctemplate.java:411) @ org.springframework.jdbc.core.jdbctemplate.query(jdbctemplate.java:466) @ org.springframework.jdbc.core.jdbctemplate.query(jdbctemplate.java:476) @ org.springframework.jdbc.core.jdbctemplate.queryforobject(jdbctemplate.java:486) @ org.springframework.jdbc.core.jdbctemplate.queryforobject(jdbctemplate.java:492)
you didn't configure datasource properly:
example:
<bean id="datasource" class="org.springframework.jdbc.datasource.drivermanagerdatasource"> <property name="driverclassname" value="com.mysql.jdbc.driver"/> <property name="url" value="jdbc:mysql://localhost:3306/test"/> <property name="username" value="root"/> <property name="password" value="password"/> </bean>
you need added database name url, in case test
Comments
Post a Comment