SQLException错误

时间:2014-03-10 07:34:26

标签: java sql

我已经建立了ODBC连接,但它仍然无法正常工作。

请一路指导,谢谢你

以下是我的代码:


package payrollapplication;
import java.sql.*;
import javax.swing.*;


/**
 *
 * @author Admin
 */
public class DBConnection {
    boolean ISCONN=false;
    boolean ISSUCC=false;
    boolean ISCONFIRM=false;


    private String NextNumber="";

    Connection Conn;
    PreparedStatement ps;
    ResultSet rs;
    Statement st;
    /** Creates a new instance of DBConnection */
    public DBConnection()
    {
        ConnectToDatabase();
    }

     public boolean ConnectToDatabase()
    {
        try
        {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            Conn=DriverManager.getConnection("jdbc:odbc:Employee");
            ISCONN=true;

        }
        catch(Exception ex)
        {
            JOptionPane.showMessageDialog(null,ex,"CONNECTION",JOptionPane.ERROR_MESSAGE);
        }

        return ISCONN;
    }

     public String getNumber()
     {
         return NextNumber;         
     }

     public void setNumber(String NXTNO)
     {
         int n;
        n=Integer.parseInt(NXTNO)+1;


         NextNumber="" + n + "";
     }

     public void  LoadEmpNo()
     {
         String SQLMax;
           try
           {
               SQLMax="SELECT Max(Emp_No) FROM MS_Employee";
              st=Conn.createStatement();
              rs=st.executeQuery(SQLMax);

              if (rs.next())
              {
                  setNumber(rs.getString(1));

              }

           }
           catch(Exception ex)
           {

           }
 }

     public boolean  FindEmployee(String SQLFIND)
     {
         try
         {
             st=Conn.createStatement();
             rs=st.executeQuery(SQLFIND);

             if (rs.next())
             {
                 ISCONFIRM=true;
             }
             else
             {
                 ISCONFIRM=false;
             }

         }
         catch(Exception ex)
         {
             ISCONFIRM=false;
         }
         return ISCONFIRM;
     }

     public boolean Add_Update_EmpMaster(String SQL,boolean ISADD_OR_UPDATE)
     {
       try
       {
         ps=Conn.prepareStatement(SQL);
         ps.executeUpdate();
         ISSUCC=true;
        }
       catch(Exception ex)
       {
          //  JOptionPane.showMessageDialog(null,ex,"CONNECTION",JOptionPane.ERROR_MESSAGE);
            ISSUCC=false;
       }

       return ISSUCC;
     }

}

这是弹出的错误:

java.sql.SQLException: [Microsoft][ODBC Driver Manager] The specified DSN contains an architecture mismatch between the Driver and Application

1 个答案:

答案 0 :(得分:1)

如果Java是64位,则需要64位驱动程序。