Hi,
Check your code:


Kind regards,

Rakesh Bhat 
PrimeSourcing(tm) 
The Global IT Services  business from i-flex - "Add Value Reduce Risk"
www.iflexsolutions.com/services/services.asp
i-flex solutions limited - Bangalore
Phone : (080) 5759-6873
Email :  Rakesh.Bhat@ iflexsolutions.com


-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, December 27, 2005 2:33 PM
To: user@struts.apache.org
Subject: ServletContext NullPointerException
Importance: Low

This is my code:

import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.NumberFormat;
import java.text.ParseException;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.text.DateFormat;
import java.util.Date;

import app.Constants;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

import javax.sql.DataSource;
import java.sql.Connection; 
import java.sql.ResultSet; 
import java.sql.Statement; 
import java.sql.DriverManager;
import java.sql.SQLException;

import org.apache.struts.action.Action;

public class MethodTest extends Action {
        public void upisULogMetoda (HttpServletRequest request, 
HttpServletResponse response, String
statusUpisaLoga, String javaKlasa, 
                                                                        String 
kategorijaUpisa, String sifraUpisa, String opis) 
                throws ServletException, IOException
        {
                HttpSession session = request.getSession();

                Connection conn = null;
                Statement stmt = null;
                ResultSet rs = null;

                        try
                        {
                
                                ServletContext context = 
servlet.getServletContext();
                                DataSource dataSource = (DataSource)
context.getAttribute("org.apache.struts.action.DATA_SOURCE");
                        Connection conn2 = dataSource.getConnection(); <----


        
                                stmt = conn.createStatement();  <------- it 
should be conn2 not conn.(I guess this is the reason )
                                String test = "INSERT INTO .....";
                                stmt.executeUpdate(test);
                                stmt.close();
        
                                conn.commit();
                                conn.close();
        
                                
                        }
                        catch(Exception e)
                        {
                                // ISKOCI I PRIKAZI PORUKU !!!!
                                e.printStackTrace();
                        }                                       
                        finally
                        {
                            try { if (rs != null) rs.close(); } catch 
(SQLException ignoreThis) {}
                            try { if (stmt != null) stmt.close(); } catch 
(SQLException ignoreThis) {}
                            try { if (conn != null) conn.close(); } catch 
(SQLException ignoreThis) {}
                        }

        }

}

In the line: ServletContext context = servlet.getServletContext();

i get NullPointerException. Why?

Tnx,
Stanislav

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to