?
Solved

Trusted Connection in a Java properties files

Posted on 2009-04-13
14
Medium Priority
?
1,091 Views
Last Modified: 2013-11-23
Hi Experts

I have a Config.properties files that cntain a trusted conenctions to a mssql database
"usvddevdb_connection_string=servername;Initial Catalog=database;Integrated Security=SSPI;"
now when I trying to display my results on a jsp page from my bean I getting this error

07:36:18,482 ERROR [STDERR] java.lang.NullPointerException
07:36:18,482 ERROR [STDERR]       at beans.SDRDataAccessDAO.getTableData(SDRDataAccessDAO.java:28)
07:36:18,482 ERROR [STDERR]       at beans.SDRBackingBean.<init>(SDRBackingBean.java:53)
07:36:18,482 ERROR [STDERR]       at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
07:36:18,482 ERROR [STDERR]       at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
07:36:18,482 ERROR [STDERR]       at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
07:36:18,483 ERROR [STDERR]       at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
07:36:18,483 ERROR [STDERR]       at java.lang.Class.newInstance0(Class.java:355)
07:36:18,483 ERROR [STDERR]       at java.lang.Class.newInstance(Class.java:308)
07:36:18,483 ERROR [STDERR]       at com.sun.faces.config.ManagedBeanFactoryImpl.newInstance(ManagedBeanFactoryImpl.java:277)
07:36:18,483 ERROR [STDERR]       at com.sun.faces.application.ApplicationAssociate.createAndMaybeStoreManagedBeans(ApplicationAssociate.java:527)
07:36:18,483 ERROR [STDERR]       at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:82)
07:36:18,483 ERROR [STDERR]       at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:53)
07:36:18,483 ERROR [STDERR]       at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:64)
07:36:18,483 ERROR [STDERR]       at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:45)
07:36:18,483 ERROR [STDERR]       at org.apache.el.parser.AstValue.getValue(AstValue.java:86)
07:36:18,483 ERROR [STDERR]       at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
07:36:18,483 ERROR [STDERR]       at org.apache.jasper.el.JspValueExpression.getValue(JspValueExpression.java:101)
07:36:18,483 ERROR [STDERR]       at javax.faces.component.UIOutput.getValue(UIOutput.java:173)
07:36:18,483 ERROR [STDERR]       at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getValue(HtmlBasicInputRenderer.java:189)
07:36:18,483 ERROR [STDERR]       at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getCurrentValue(HtmlBasicRenderer.java:320)
07:36:18,483 ERROR [STDERR]       at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeEnd(HtmlBasicRenderer.java:200)
07:36:18,483 ERROR [STDERR]       at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:836)
07:36:18,483 ERROR [STDERR]       at javax.faces.component.UIComponent.encodeAll(UIComponent.java:896)
07:36:18,483 ERROR [STDERR]       at javax.faces.render.Renderer.encodeChildren(Renderer.java:137)
07:36:18,483 ERROR [STDERR]       at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:812)
07:36:18,483 ERROR [STDERR]       at javax.faces.component.UIComponent.encodeAll(UIComponent.java:886)
07:36:18,483 ERROR [STDERR]       at javax.faces.component.UIComponent.encodeAll(UIComponent.java:892)
07:36:18,483 ERROR [STDERR]       at com.sun.faces.application.ViewHandlerImpl.doRenderView(ViewHandlerImpl.java:245)
07:36:18,483 ERROR [STDERR]       at com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:176)
07:36:18,483 ERROR [STDERR]       at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:108)
07:36:18,483 ERROR [STDERR]       at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:189)
07:36:18,483 ERROR [STDERR]       at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:106)
07:36:18,483 ERROR [STDERR]       at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
07:36:18,483 ERROR [STDERR]       at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
07:36:18,483 ERROR [STDERR]       at javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
07:36:18,483 ERROR [STDERR]       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
07:36:18,483 ERROR [STDERR]       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
07:36:18,483 ERROR [STDERR]       at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
07:36:18,483 ERROR [STDERR]       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
07:36:18,483 ERROR [STDERR]       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
07:36:18,483 ERROR [STDERR]       at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
07:36:18,483 ERROR [STDERR]       at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
07:36:18,483 ERROR [STDERR]       at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
07:36:18,483 ERROR [STDERR]       at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
07:36:18,483 ERROR [STDERR]       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
07:36:18,483 ERROR [STDERR]       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
07:36:18,483 ERROR [STDERR]       at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
07:36:18,483 ERROR [STDERR]       at org.apache.catalina.authenticator.SingleSignOn.invoke(SingleSignOn.java:393)
07:36:18,483 ERROR [STDERR]       at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
07:36:18,483 ERROR [STDERR]       at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
07:36:18,483 ERROR [STDERR]       at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
07:36:18,483 ERROR [STDERR]       at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
07:36:18,483 ERROR [STDERR]       at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
07:36:18,483 ERROR [STDERR]       at java.lang.Thread.run(Thread.java:619)


Now when I debugged this error I found this that my getConnection() is null. I have tested this iwht a user name and password on my config file andf it work 100% but soon as I change my connection to a trusted it gives me a Error

Can an Expert assist

Tx



package beans;
 
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Properties;
 
 
import javax.resource.spi.UnavailableException;
 
 
import net.sourceforge.jtds.jdbc.Driver;
 
public class SDRDataAccessDAO {
    private static PreparedStatement prepStatement = null;
    private static ResultSet sqlSet = null;
    private static String driverStr = getConn();
    private static Connection conn = null;
   
 
    public ArrayList<SDRDataAccess> getTableData() {
        ArrayList<SDRDataAccess> returnVal = new ArrayList<SDRDataAccess>();
        try {
            Connection con = getConnection();
            String sql = "SELECT * FROM AnthonioFile";
            prepStatement = con.prepareStatement(sql);
            sqlSet = prepStatement.executeQuery();
            SDRDataAccess access = new SDRDataAccess();
            while (sqlSet.next()) {
                access.setId(sqlSet.getInt(1));
                access.setStatus(sqlSet.getString(2));
                access.setMonth1(sqlSet.getString(3));
                access.setMonth2(sqlSet.getString(4));
                access.setMonth3(sqlSet.getString(5));
                access.setMonth4(sqlSet.getString(6));
                access.setMonth5(sqlSet.getString(7));
                access.setMonth6(sqlSet.getString(8));
                access.setMonth7(sqlSet.getString(9));
                access.setMonth8(sqlSet.getString(10));
                access.setMonth9(sqlSet.getString(11));
                access.setMonth10(sqlSet.getString(12));
                access.setMonth11(sqlSet.getString(13));
                access.setMonth12(sqlSet.getString(14));
                returnVal.add(access);
                access = new SDRDataAccess();
                
                
            }
 
        } catch (Exception e) {
            e.printStackTrace();
        }
 
        return returnVal;
        
    }
    
 
        public SDRMonthDeployHeader getMonthDeploy() {
        SDRMonthDeployHeader monthdeploy = new SDRMonthDeployHeader();
        try {
            Connection conn = getConnection();
            String sql = "SELECT * FROM View_MonthDeploy";
            prepStatement = conn.prepareStatement(sql);
            sqlSet = prepStatement.executeQuery();
            
            while (sqlSet.next()) {
                monthdeploy.setMonth_1_Deploy(sqlSet.getString(2));
                monthdeploy.setMonth_2_Deploy(sqlSet.getString(4));
                monthdeploy.setMonth_3_Deploy(sqlSet.getString(6));
                monthdeploy.setMonth_4_Deploy(sqlSet.getString(8));
                monthdeploy.setMonth_5_Deploy(sqlSet.getString(10));
                monthdeploy.setMonth_6_Deploy(sqlSet.getString(12));
                monthdeploy.setMonth_7_Deploy(sqlSet.getString(14));
                monthdeploy.setMonth_8_Deploy(sqlSet.getString(16));
                monthdeploy.setMonth_9_Deploy(sqlSet.getString(18));
                monthdeploy.setMonth_10_Deploy(sqlSet.getString(20));
                monthdeploy.setMonth_11_Deploy(sqlSet.getString(22));
                monthdeploy.setMonth_12_Deploy(sqlSet.getString(24));
                break;       
            }
 
        } catch (Exception e) {
            e.printStackTrace();
        }
 
        return monthdeploy;
        
    }
 
    public void setTable(SDRDataAccess access){
	    try {
	        Connection con = getConnection();
            String sql = getUpdateSQLString(access);
            prepStatement = con.prepareStatement(sql);
            int numUpdates = prepStatement.executeUpdate();
            if (numUpdates != 1){
                throw new UnavailableException("No update was performed");
            }    
    } catch (Exception e) {
        e.printStackTrace();
    }
	}
    
    private Connection getConnection(){
        if (conn == null){
        try {
            Class.forName("net.sourceforge.jtds.jdbc.Driver");
            Driver driver = new Driver();
            Properties prop = new Properties();
            conn = driver.connect(driverStr,prop);
        } catch (Exception e) {
                e.printStackTrace();
        }
        }
        return conn;       
    }
    
 
    private String getUpdateSQLString(SDRDataAccess access){
                String sql = "UPDATE AnthonioFile " +
        		"SET Status = '" + access.getStatus() + "'," +
        		"Month1 =  '" + access.getMonth1() + "'," +
        		"Month2 =  '" + access.getMonth2() + "'," +
        		"Month3 =  '" + access.getMonth3() + "'," +
        		"Month4 =  '" + access.getMonth4() + "'," +
        		"Month5 =  '" + access.getMonth5() + "'," +
        		"Month6 =  '" + access.getMonth6() + "'," +
        		"Month7 =  '" + access.getMonth7() + "'," +
        		"Month8 =  '" + access.getMonth8() + "'," +
        		"Month9 =  '" + access.getMonth9() + "'," +
        		"Month10 =  '" + access.getMonth10() + "'," +
        		"Month11 =  '" + access.getMonth11() + "'," +
        		"Month12 =  '" + access.getMonth12() + "'" +
        		"where ID = " + access.getId();
        return sql;
    
        
    }
    
    private static String getConn() {
        StringBuffer conn = new StringBuffer();
        conn.append(SDRBackingBean.getProp().getProperty("usvddevdb_connection_string"));
        return conn.toString();
 
}
    
    
    
    
   
}

Open in new window

0
Comment
Question by:ablsysadmin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 10
  • 2
  • 2
14 Comments
 

Author Comment

by:ablsysadmin
ID: 24135707
Hi

What I have picked up when I did my debug again is that when it get to statement

            Connection con = getConnection();
            String sql = "SELECT * FROM AnthonioFile";
            prepStatement = con.prepareStatement(sql);
            sqlSet = prepStatement.executeQuery();


it catch an Exception. What I also pciked up is that "con is = null"

Thanks
0
 

Author Comment

by:ablsysadmin
ID: 24135750
Error Message from my previouse statement

Caused by: java.lang.NullPointerException
      at beans.SDRDataAccessDAO.getTableData(SDRDataAccessDAO.java:29)
      at beans.SDRBackingBean.<init>(SDRBackingBean.java:53)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
      at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
      at java.lang.Class.newInstance0(Class.java:355)
      at java.lang.Class.newInstance(Class.java:308)
      at com.sun.faces.config.ManagedBeanFactoryImpl.newInstance
0
 
LVL 11

Assisted Solution

by:anilallewar
anilallewar earned 500 total points
ID: 24136035
Did you have access rights on the MSSQL database using your NT id? To be able to connect with integrated security your NT id needs to be added as a user to the SQL database.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 16

Expert Comment

by:ai_ja_nai
ID: 24136492
the .properties file has noot been parsed well (maybe the value is missing?) and the variable that get that value assigned remains initialized to 'null'; at run time, when it gets read, it returs its 'null' value and the JVM raises the exception
0
 

Author Comment

by:ablsysadmin
ID: 24136685
Hi

Yes I have access to thye MSSQL database with my NT id. I have created a TEST connections to see if it will work in this and my variable con value is null. Please check this test code posted below and see if I am doing anything wrong
   public static void testDBConnection(java.sql.Connection con){
        
        String strCnn = "Server=SQL2005TEST;DatabaseName=mdb;Trusted_Connection=True";
        if (con == null){
            try {
                Class.forName("net.sourceforge.jtds.jdbc.Driver");
                Driver driver = new Driver();
                Properties property = new Properties();
                con = driver.connect(strCnn,property);
                if (con == null){
                    System.out.println("Connection is null");
                    
                    
                }else{  
                    System.out.println("Connection is not null");
                }
            } catch (Exception e) {
                    e.printStackTrace();
            }
            }
              
    }
    
    public static void main(String[] str){
        java.sql.Connection con = null;
        testDBConnection(con);
    }

Open in new window

0
 

Author Comment

by:ablsysadmin
ID: 24137169
Hi

I just tested by changing
from
String strCnn = "Server=SQL2005TEST;DatabaseName=mdb;Trusted_Connection=True";
To
String strCnn = "jdbc:jtds:sqlserver://SQL2005TEST/MDB;user=username;password=passw";

and the variable "con" value is not null

So this tell me that its my StrCnn that wrong ?
0
 

Author Comment

by:ablsysadmin
ID: 24137341
HI

I am trying different option and I tired this StrCnn
String strCnn = "jdbc:jtds:sqlserver://SQL2005TEST/MDB;Integrated Security=SSPI";

and my Error message is now

java.sql.SQLException: I/O Error: SSO Failed: Native SSPI library not loaded. Check the java.library.path system property.
      at net.sourceforge.jtds.jdbc.TdsCore.login(TdsCore.java:614)
      at net.sourceforge.jtds.jdbc.ConnectionJDBC2.<init>(ConnectionJDBC2.java:344)
      at net.sourceforge.jtds.jdbc.ConnectionJDBC3.<init>(ConnectionJDBC3.java:50)
      at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:182)
      at beans.SDRBackingBean.testDBConnection(SDRBackingBean.java:310)
      at beans.SDRBackingBean.main(SDRBackingBean.java:327)
Caused by: java.io.IOException: SSO Failed: Native SSPI library not loaded. Check the java.library.path system property.
      at net.sourceforge.jtds.jdbc.TdsCore.sendMSLoginPkt(TdsCore.java:1889)
      at net.sourceforge.jtds.jdbc.TdsCore.login(TdsCore.java:587)
      ... 5 more
0
 

Author Comment

by:ablsysadmin
ID: 24145071
Good Morning Experts

Any feedback
0
 
LVL 16

Expert Comment

by:ai_ja_nai
ID: 24146635
the library you are looking for has not been included in the CLASSPATH
0
 

Author Comment

by:ablsysadmin
ID: 24147314
Hi

I searched on google and found that it related to a ntlmauth.dll which I got and fixed it from my windows vista machine. I then deployed the EAR file to a linux box and got this error.
14:22:02,674 ERROR [STDERR] java.sql.SQLException: Single-Sign-On is only supported on Windows. Please specify a user name.

Question
Should I include this classpath?
if yes how do it do it?

Please can you assist with this :-(

Thanks :-(
0
 

Author Comment

by:ablsysadmin
ID: 24147327
O Sorry this is the connection string that I am using

usvddevdb_connection_string=jdbc:jtds:sqlserver://sqltest:1433/database;Integrated Security=SSPI;
0
 
LVL 11

Accepted Solution

by:
anilallewar earned 500 total points
ID: 24222470
The intergrated Security option is available only on Windows m/c. Further as far as my knowledge goes SQL 2005 is avilable only on Windows and you might not have JDBC driver for Linux.

The ntlmauth.dll has to be available under system32 folder and you would need to load it before calling creating the connection. The sample code under you class definition would be like below. Ensure that you load the DLL only once in the class level static block.

static{
         try{
                System.load("C:\WINDOWS\system32\ntlmauth.dll");
        }catch (Exception oException) {
                System.out.println("Exception in ..static block of loading dll "+oException.getMessage());
       }
}
0
 

Author Comment

by:ablsysadmin
ID: 24791859
Thanks its working
0
 

Author Closing Comment

by:ablsysadmin
ID: 31569787
It works
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month13 days, 15 hours left to enroll

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question