[opencms-dev] Content Definition MySQL help

Rene Hinojosa R_Hinojosa at Cityofsouthfield.com
Wed Aug 20 16:17:01 CEST 2003


Greetings,

I've been working on a new module and have come upon a snag. I keep recieving NullPointerException when I try to execute the following method:

        public static Vector getCalendarList(int year, int month) {
		Vector list = new Vector();
                	Connection con = null;
		Statement statement = null;
		ResultSet res = null;
		try {
                        con = DriverManager.getConnection(c_pool);
                        
                        String sql = "select * from calendar where eventdate like '"+year+"-"+month+"-%'";
                        statement = con.createStatement();
                        
			res = statement.executeQuery(sql);
                        //test = res.getWarnings().toString();
			while(res.next()){
				CalendarContentDefinition cal = new CalendarContentDefinition();
				cal.setId(res.getInt(1));
                                cal.setEventDate(res.getString(2));
                                cal.setEventSection(res.getString(3));
				cal.setEventTitle(res.getString(4));
                                cal.setEventDetail(res.getString(5));
				list.addElement( cal );
			}
		}catch(Exception e) {
			System.err.println("Exception in CalendarContentDefinition.getCalendarList()!");
                        test = e.toString();
			e.printStackTrace();
		}finally{
			try{
				res.close();
			}catch (Exception e) {
				// ignore the exception
			}
            try{
				statement.close();
			}catch (Exception e) {
				// ignore the exception
			}
            try{
				con.close();
			}catch (Exception e) {
				// ignore the exception
			}
		}
		return list;
	} 

I have another method which does the same thing but uses a different sql statement(select * from calendar). It works fine but the LIKE statement does not. I tested the statement in mysql and it works. I've created a test program and it works there also. Am I missing something? I've also tried using the preparedStatement way also.

Any suggestions would be greatly appreciated.

Thanks,

Rene




More information about the opencms-dev mailing list