This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
PreparedStatement st= conn.prepareStatement("select sum(amount) from tbl_daily_collection where user_code in (select distinct subdiv from tbl_admcd where div = ?)"); st.setInt(1,user); ResultSet rs = st.executeQuery();
Are you sure the subquery returns any values in java? Try running the subquery in java and see.
Not that java has anything to do with it, its most likely a user ownership issue. Often times you need to specify the table owner in the table name such as dbo.tbl_admcd. Query analyzers often fill in missing info without telling you which is why it appears to work outside of java, your query analyzer is being clever and it probably should give the same error java is reporting, that there subquery is returning no data for the in clause.