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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:11:22+00:00 2026-05-22T16:11:22+00:00

Anybody know what’s wrong with my code? I am using a simple INSERT statement

  • 0

Anybody know what’s wrong with my code? I am using a simple INSERT statement (as opposed to the regular PreparedStatement because I am trying to utilize mySQL’s AES_ENCRYPT/DECRYPT functions. I do not know how to use them with the regular set up of the PreparedStatements. with all the funky question marks.

I keep getting the classic:

com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails (video_game_db.login, CONSTRAINT login_ibfk_1 FOREIGN KEY (cust_ID) REFERENCES customer (cust_ID))

Of course, it’s driving me batty.

I spent all night trying to make the regular JDBC implementation of the cipher “stuff” work. In the end, I could only encrypt the strings, but could not decrypt them. I figured it had to do something with mySQL as opposed to JDBC, as before I input them into the database they decrypted fine, but afterwards I could get it to work.


Please take a look at my JDBC table DDL and DML statements below:

DDL

Statement s = conn.createStatement();
s.executeUpdate("CREATE TABLE customer("+"cust_ID CHAR(10) NOT NULL,"+"PRIMARY KEY(cust_ID),"+"first_Name CHAR(30)NOT NULL,mI CHAR(2),last_Name CHAR(50)NOT NULL,street_Name CHAR(50),city CHAR(30) NOT NULL,state CHAR(50) NOT NULL,"
            +"zip_Code CHAR(5) NOT NULL, home_Phone CHAR(12) UNIQUE, referrer CHAR(30), quantity INTEGER NOT NULL, item_No CHAR(10))"); 
s.executeUpdate("CREATE TABLE login ("+"user_Name CHAR(50) NOT NULL,"+"PRIMARY KEY(user_Name),"+"pass_Word CHAR(50)NOT NULL, cust_ID CHAR(10))");  

DML

public static void setCustTable(String cust_ID, String lName, String fName, String mI, String street_Name, String city, String state,
  String zip_Code, String home_Phone, String referrer, int quantity, String itemNo)throws IOException, SQLException 
{

// connect to database
try
{    

    PreparedStatement stat = conn.prepareStatement("INSERT INTO customer (cust_ID, first_Name, mI, last_Name, street_Name, city, state, zip_Code, home_Phone, referrer, quantity, item_No)"
                + " VALUES (?,?,?,?,?,?,?,?,?,?,?,?)");

    stat.setString(1, cust_ID);
    stat.setString(2, fName);
    stat.setString(3, mI);
    stat.setString(4, lName);
    stat.setString(5, street_Name);
    stat.setString(6, city);
    stat.setString(7, state);
    stat.setString(8, zip_Code);
    stat.setString(9, home_Phone);
    stat.setString(10, referrer);
    stat.setInt(11, quantity);
    stat.setString(12, itemNo);

    stat.executeUpdate();
}  

 catch (SQLException e) 
{
    e.printStackTrace();
    throw e;
}

**********************************************************************************



public static void insertLoginData(String username5, String password5, String custID5)throws IOException, SQLException, NoSuchAlgorithmException, InvalidKeyException

{
    Statement s = conn.createStatement();
    String insert="INSERT INTO login VALUES('username5', AES_ENCRYPT('text','password5'),'custID5')";
    s.executeUpdate(insert);
  • 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-05-22T16:11:23+00:00Added an answer on May 22, 2026 at 4:11 pm

    For what it worth, I don’t see any insert into customer. Error message tells that there is a foreign key constraint from login to
    customer. So customer entry must exist prior to login insert.


    Was there intention to quote ‘username5’? I think it is a parameter to method but insert uses literal.

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

Sidebar

Related Questions

Anybody know if it's possible? I'm trying to get the data by using the
Anybody know what my DLLImport statement should look like here: extern C __declspec(dllexport) long
Anybody know of a way to batch NHibernate queries using NHibernate.Linq like you can
Anybody know ,what is the logic behind Thread.sleep in java? . Are they using
Does anybody know how to create a text field using PyGTK that only accepts
Anybody know how to create code snippets in Mozilla Bespin. Its strange that there's
Anybody know how to deploy a simple Flask application on Webfaction? I know Webfaction
Anybody know how can we change the background of our webpage without using custom
Anybody know which is the easy way to insert a json string in cassandra.
Anybody know of a way to copy a file from path A to path

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.