3 Replies Latest reply: Jan 10, 2012 12:55 PM by Sruthi RSS

    java.sql.SQLException: ODBC Driver Manager

    Sruthi
      Hi,

      I am new to JSP & Web tech. I am trying to access SQL server from validation.jsp. The piece of code used for the same is given below. TestDSN is the System DSN I have added in ODBC Data Source Administrator(All Control Panel Items\Administrative Tools). I am using Tomcat 7.

      ---------------------------------------------------------------------------------------------------------------------------
      <%
           String user=request.getParameter("t1");
           String pass=request.getParameter("t2");

           try{

                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
           Connection test=DriverManager.getConnection("jdbc:odbc:TestDSN","sa","abcd");
           Statement st=test.createStatement();
           String sqlQuery = "Select username,password from dbo.userlog where username=\'" + user + "\'";
      ResultSet rs=st.executeQuery( sqlQuery );
                int userflag = 0;

      ---------------------------------------------------------------------------------------------------------------------------

      I am able to access database and do the validation and get the direction to next page in my 32 bit PC (Windows 7). But while trying the same from 64 bit PC, the following message is thrown *"Error occurred java.sql.SQLException: [Microsoft][ODBC Driver Manager] The specified DSN contains an architecture mismatch between the Driver and Application"*

      Could you please help me.

      Thank you.
      Sruthi
        • 1. Re: java.sql.SQLException: ODBC Driver Manager
          EJP
          If you are using 32-bit Java on 64-bit Windows you need to define a DSN using the 32-bit ODBC driver in the ODBC Data Source Administrator.
          • 2. Re: java.sql.SQLException: ODBC Driver Manager
            DrClap
            Could I point out a few bad practices in your posted code?

            (1) Using scriptlets in a JSP.

            (2) Using the JDBC-ODBC driver to access a database other than MS Access.

            (3) Generating SQL via string concatenation instead of using a PreparedStatement.

            I'm also willing to guess that you have done these further bad practices, although your posted code doesn't clearly demonstrate them:

            (4) Storing passwords in clear-text in the database.

            (5) Failing to close your connections in a finally-block.

            As you say, you are learning Java-based web technologies. But really, you have started out quite badly. I would suggest you seek out some more experienced supervision to lead you into better habits.
            • 3. Re: java.sql.SQLException: ODBC Driver Manager
              Sruthi
              EJP,

              Thanks for the hint. I was using 32 bit Java & 32 bit Tomcat. Using 64 bit versions the error is no more seen.

              Few more info:
              http://www.liferay.com/community/forums/-/message_boards/message/4283098


              DrClap,

              Thanks for the detailed suggestions too. Unfortunately it happened to be my first jsp & was trying to extend a java program and see the outcome.

              Thank you.
              Sruthi