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

  • Home
  • SEARCH
  • 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 7753203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:59:47+00:00 2026-06-01T11:59:47+00:00

I am writing an access control program in Java that captures passwords using JPasswordField

  • 0

I am writing an access control program in Java that captures passwords using JPasswordField. Since the jpasswordfield.getPassword() method returns values as chars, I need to know how to save the char value in a MYSQL database using preparedstatement. I am using MYSQL fields password char[100] for storing the passwords.

Please help.

  • 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-01T11:59:48+00:00Added an answer on June 1, 2026 at 11:59 am

    I made a simple example of storing a char array in a database using a prepared statement. I used Java DB instead of MySQL as it is included in the JDK (jdk1.7.0/db/lib/derby.jar) it shouldn’t matter for this example.

    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    
    
    public class Example {
        public static void main(String[] args) throws SQLException {
            try (Connection connection = DriverManager.getConnection("jdbc:derby:memory:sampleDB;create=true");
                 Statement statement = connection.createStatement()
            ) {
                char[] pw = "password".toCharArray();
                statement.execute("create table sample(pw char(10))");
    
                try (ResultSet resultSet = statement.executeQuery("select * from sample");
                     PreparedStatement preparedStatement = connection.prepareStatement("insert into sample values (?)")
                ) {
                    for (int i = 1; i <= 10; i++) {
                        preparedStatement.setString(1, new String(pw) + i);
                        preparedStatement.execute();                    
                    }
    
                    while (resultSet.next()) {
                        System.out.println(resultSet.getString(1));
                    }
                }
            }
        }
    }
    

    As others already said, you should not store passwords in plaintext in the database. Instead you should store a hash of it (SHA-1 Hash in Java).

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

Sidebar

Related Questions

I am writing a program in VS 2005 and I wanna control the access
I am maintaining a program that reads records from a Access '97 table using
I am writing an activex control that will access the parallel port and write
I'm writing a C# program that monitors a dedicated Gmail account using POP3 for
OK, so instead of writing a whole bunch of access control specs, and duplicating
I'm writing a cgi-bin program for my Sheevaplug (running the default Ubuntu install) that
I'm writing a quick web page to control access to a web based repository
I'm writing item template for repeater in separate control, and then I'm using following
When writing rules for access control in yii controllers, possible parameters to be set
I am writing a script using jQuery to add multiple control boxes(divs) to a

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.