I haven't tried it myself but you could consider using JDe Survey which according to themself is:
JD eSurvey is an open source enterprise survey web application written in Java and based on the Spring Framework. Check out the tutorial videos to find out more about the application features.
For more information see link above or http://www.jdsoft.com/jdesurvey/ where they on the front page say the following about JDe Survey:
- Intuitive Design —
JD eSurvey delivers an exceptionally intuitive, easy-to-use interface that helps you manage survey data
- Safe and Secure — Take a peek at how JD eSurvey's security system safeguards your privacy and content with easy and quick steps
- Powerful Logic — Branching, randomization and piping are just a few of the simple and valuable manipulation at the survey
- Great Features — JD eSurvey is packed with a variety of useful features, including survey statistics and a whole lot more
Adaptable, versatile and user-friendly. Powered by a range of features from branching and randomization, to piping for survey control, to a diverse list of question types JD eSurvey is the ideal solution for any individual or organization.
JD eSurvey is a java open source survey tool web application written in Java and based on the Spring Framework and Hibernate ORM.
JD eSurvey is Free and open source software (FOSS) licensed under the GNU Affero General Public License Version 3. The source code for JD eSurvey is available for viewing and download at our download page.
In other words it should meet your requirements of: Java, multiple choice and text answers, randomizing answers1, logic flow, export to (Excel, csv and SPSS)1. Not sure about which database it uses.