Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9140979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:35:13+00:00 2026-06-17T09:35:13+00:00

I am struggling with SQL Server 2005 and JDBC. I have a stored procedure:

  • 0

I am struggling with SQL Server 2005 and JDBC. I have a stored procedure:

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

ALTER proc [dbo].[sp_logincheck]
    @username as nvarchar(50),
    @password as nvarchar(50)
as
begin
    select * 
    from users 
    where user_name = @username 
      and password = @password 
      and is_active = 'Yes'
end

And my User class is:

import java.sql.*;

public class User {
    private String username;

    private User(String username){
        this.username = username;
    }

    public static User login(String username, char [] password) throws SQLException{
        if(username == null || password == null){
            throw new IllegalArgumentException("Illegal arguments passed to method");
        }
        if(login1(username, password)){
            return new User(username);
        }
        return null;
    }

    private static boolean login1(String username, char [] password) throws SQLException{
        Connection connection = null;
        CallableStatement statement = null;
        try{
            connection = DriverManager.getConnection(AppParameters.dbURL, AppParameters.dbUsername, AppParameters.dbPassword);
        }catch(SQLException e){
            throw e;
        }
        try{
            statement = connection.prepareCall("{ ? = call dbo.sp_logincheck(?,?) }");
            statement.registerOutParameter(1, Types.INTEGER);
            statement.setString(2, username);
            statement.setString(3, new String(password));
            statement.execute();
            if(statement.getInt(1) == 1){
                System.out.println("Login Successfull");
                return true;
            }
            System.out.println("Login Failed");
            return false;
        }catch(SQLException sqle){
            sqle.printStackTrace();
            throw sqle;
        }finally{
            try{
                statement.close();
            }catch(Exception e){
            }
            try{
                connection.close();
            }catch(Exception e){
            }
        }
    }

    public  String getUsername(){
        return username;
    }
}

Calling login() method always prints Login Failed. How can I use stored procedure in SQL Server and using JDBC to perform user login? Or going with raw SQL statements is better? Please guide me on this.

EDIT:

I would also like to know how to get the ResultSet from the above stored procedure, as I have a select query inside the stored procedure.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:35:14+00:00Added an answer on June 17, 2026 at 9:35 am

    Try the following:

    ResultSet rs = statement.executeQuery();
    if (! rs.isLast()) {
        // match
    } else {
        // no match
    }
    

    Also, I’d recommend to select only the count (select count(*) as cnt from ...), and use like int count = rs.next().getInt("cnt");

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am struggling understanding what a clustered index in SQL Server 2005 is. I
I've been struggling to get a Java program to connect to MS SQL Server,
I have a SQL Server database with two values I'm interested in: dtime -
I'm using the INFORMATION_SCHEMA views in Sql Server 2005 & 2008 to obtain metadata
I've been struggling with precision nightmare in Java and SQL Server up to the
Hi all I am new to batch files and struggling.I am using sql server
I'm struggling to find the right functions with SQL Server 2008 to rectify any
I've been struggling with a SQL Azure cross-server copy for a bit now -
Struggling with this a bit in SQL Server, any ideas? Given this data (ID
I am having a tough time struggling with XML within Sql Server 2008. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.