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 8074485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:39:55+00:00 2026-06-05T14:39:55+00:00

I am working on a personal project. I am creating a punch clock program

  • 0

I am working on a personal project. I am creating a punch clock program so the part that I need help with, is where the user inputs the uid in the jTextField. So, I need to retrieve the uid(#######) and then search for that uid in the database with a sql statement. So this is what I have so far. the problem is that there is a red line under jTextField1.getText and when and when I run it, says =

"setInt(int,int) in java.sql.PreparedStatement cannot be applied to (int,java.lang.String) pstmt.setInt(1, jTextField1.getText());"

Any help is appreciated. Thank you.

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:
    try{
        stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
        String sql = "SELECT * FROM Students WHERE STUDENTID = ?";
        PreparedStatement pstmt = con.prepareStatement(sql);
        pstmt.setInt(1, jTextField1.getText()); // Retrieve uid from jTextField
        ResultSet rs = pstmt.executeQuery();
        while(rs.next()){
            String first = rs.getString(2);
            String last = rs.getString(3);
            String hours = rs.getString(6);

            fName.setText(first);
            lName.setText(last);
            tHours.setText(hours);
        }
    }
    catch(SQLException err){
        JOptionPane.showMessageDialog(Student.this, err.getMessage());
    }

}
  • 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-05T14:39:57+00:00Added an answer on June 5, 2026 at 2:39 pm

    As you can see from the documentation, the setInt() method takes in both parameters as int.

    public void setInt(int parameterIndex,
                       int x)
    

    So,You need to change this:

     pstmt.setInt(1, jTextField1.getText()); 
    

    to:

     pstmt.setInt(1, Integer.parseInt(jTextField1.getText())); 
    

    because the getText() method returns a String.

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

Sidebar

Related Questions

I am working on a personal project creating a punch clock in java. Since
I'm working on a personal project involving Javascript, and as part of that project,
I am working on a personal project where I need to manipulate values in
I'm working on a personal project problem. It's a donation management model. I need
I am working on a personal project that uses a custom config file. The
I'm working a personal project that's going to include a home-screen widget updated with
I'm working on a personal project involving microphones in my apartment that I can
As part of a personal project I am working on I took a small
I'm working on a personal project involving map-making tools for a tabletop game that
I'm working on a personal learning project to help me understand how to use

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.