Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java SQL查询/存储过程未返回值_Java_Sql Server_Sql Server 2008_Jakarta Ee - Fatal编程技术网

Java SQL查询/存储过程未返回值

Java SQL查询/存储过程未返回值,java,sql-server,sql-server-2008,jakarta-ee,Java,Sql Server,Sql Server 2008,Jakarta Ee,我有一个执行查询和存储过程的类。我面临的问题是,execute result没有返回值,SP output参数也没有返回值。当我在SQL编辑器中执行这些SP和查询时,它工作正常 package com.airtel.mail; import java.io.File; import java.io.IOException; import java.sql.CallableStatement; import java.sql.Connection; import java.sql.DriverM

我有一个执行查询和存储过程的类。我面临的问题是,execute result没有返回值,SP output参数也没有返回值。当我在SQL编辑器中执行这些SP和查询时,它工作正常

package com.airtel.mail;

import java.io.File;
import java.io.IOException;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Types;
import java.util.ArrayList;

import javax.mail.internet.NewsAddress;

import org.apache.poi.hssf.record.formula.functions.Ipmt;

import com.auxilii.msgparser.Message;
import com.auxilii.msgparser.MsgParser;


public class Utility {

    public static Connection getConnection() throws SQLException{
        Connection conn= null;
        try{
            Class.forName("net.sourceforge.jtds.jdbc.Driver");
            conn = DriverManager.getConnection("jdbc:jtds:sqlserver://(address:port)","(user)", "(password)");
            if(conn == null){
                System.out.println("Connection Failed");
            }else{
                System.out.println("Connection Success");
            }
        }catch(Exception e){
            e.printStackTrace();
        }
        return conn;
    }

    public static String getLeaEmailId(String emailID)
    {
        String btStatus = "";
        Connection conn = null;
        Statement stmt = null;        
        ResultSet rs = null; 
        String SQLQUERY = "select Lea_EmailId from dbo.Lea_add where LEA_Number=(select varLeaNumber  from dbo.TR_AddTarget where  varEmailId='"+emailID+"' and dtAuthorizationDate=(select MAX(dtAuthorizationDate) from TR_AddTarget where varEmailId='"+emailID+"'))";
        try {
            conn = getConnection();
            stmt = conn.createStatement();
            rs = stmt.executeQuery(SQLQUERY);
            System.out.println("SQLQUERY <><> " + SQLQUERY);
            if(rs.next()) {
                btStatus = rs.getString("Lea_EmailId");
            }

        } catch (Exception e) {
            e.printStackTrace();
        }finally{
            try {
                conn.close();
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        return btStatus;

    }


    public static String[] getFwdMailId(String emailId) throws SQLException {
        System.out.println("EMAIL ID INSIDE getFwdEmailID <><> " + emailId);
        CallableStatement cstsmt = null;
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        Connection conn = null;
        String fwdId = "";
        String nodalId = "";
        String fwdNodal[] = new String[2]; 
        try {
            conn = getConnection();
            cstsmt = conn.prepareCall("{call dbo.Usp_GetLeaIDMain(?,?,?)}");
            cstsmt.setString(1, emailId);
            cstsmt.registerOutParameter(2, Types.VARCHAR);
            cstsmt.registerOutParameter(3, Types.VARCHAR);
            cstsmt.execute();
            fwdId = cstsmt.getString(2); 
            nodalId = cstsmt.getString(3);
            System.out.println("LEA ID INSIDE PROCEDURE<><><> "+ fwdId);
            System.out.println("NODAL ID INSIDE PROCEDURE<><><> "+ nodalId);
            fwdNodal[0] = fwdId;
            fwdNodal[1] = nodalId;
        }catch (Exception e) {
            e.printStackTrace();
        }finally{
            try{
                cstsmt.close();
                conn.close();
            }catch (SQLException e) {
                e.printStackTrace();
            }

            }
        return fwdNodal;
    }

    public static String[] getEmailPasswd(){
        String emailPasswd[] = new String[2];
        Connection conn = null;
        Statement stmt = null;        
        ResultSet rs = null; 
        String email = "";
        String passwd = "";
        String SQLQUERY = "SELECT Email_Id, Email_Passwd FROM Java_Config";
        try {
            conn = getConnection();
            stmt = conn.createStatement();
            rs = stmt.executeQuery(SQLQUERY);
            if(rs.next()) {
                email = rs.getString("Email_Id");
                passwd = rs.getString("Email_Passwd");
            }

            emailPasswd[0] = email;
            emailPasswd[1] = passwd;

        } catch (Exception e) {
            e.printStackTrace();
        }finally{
            try {
                conn.close();
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        return emailPasswd;
    }

    public static void main(String[] args) {
        String str = "deepak.deemca@gmail.com";
        try{
            String s = getLeaEmailId(str);
            System.out.println("ID via QUERY <><> " +s );
            String str1[] =  getFwdMailId(str);
            System.out.println("fl <><> " +str1[0]);
            String str2[] = getEmailPasswd();
            System.out.println("str2 [0] and str2[1] <><> " + str2[0] +"<><><><" +str2[1]);
        }catch (Exception e) { 
            e.printStackTrace();
            // TODO: handle exception
        }
    }


}

请告诉我们错误发生在哪一行!getLeaEmailId中的SQL查询易受攻击。为什么不尝试单独执行SQL查询,并尝试查看它是否返回任何行。getLeaEmailId和getFwdMailId在getEmailPasswd工作时不工作。