-2
int re = 0;
for (int t=0; t<mat1.length-1; t++){
    if(mat1[t]=="A"){
        re=re+00;
    }else if(mat1[t]=="T"){
        re=re+01;
    }else if(mat1[t]=="G"){
        re=re+10;
    }else if(mat1[t]=="C"){
        re=re+11;
    }

    System.out.println(mat1[t]);
}

I want these codes translated from the binary we choose to ASCII and then the ASCII will know the values

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
Sam
  • 5
  • 4
  • you mean you want the final string converted from binary to decimal format or ASCII or what exactly? – gabbar0x Dec 10 '15 at 13:39
  • 2
    You do realize that 11 doesn't actually mean "binary 11", right? It's just the decimal number 11. Also, you need to read http://stackoverflow.com/questions/513832. I'm afraid your question is currently really unclear, especially as you're not using `re` at the end... – Jon Skeet Dec 10 '15 at 13:39

3 Answers3

0

Sam, you'll need to create some sort of translation table so as to know which makeshift binary bit relates to whichever character and I say makeshift because 00 is nothing equivalent to the letter "A" in binary. The same applies to the binary representation for the other characters you provide as well. What the binary representation might be is irrelevant at this point since you can do whatever you want for your specific purpose. If possible though, proper representation is the way to go for more advanced functionality later on down the road AND you wouldn't need a translation table because all you would need to do is convert the character ASCII value to binary, like this:

// 65 is the ASCII value for the letter A.
String letterAis = String.valueOf(Integer.toBinaryString(0x100 + 65).substring(2));


ALPHABET IN (8 bit) BINARY, CAPITAL LETTERS

A    01000001       N    01001110
B    01000010       O    01001111
C    01000011       P    01010000
D    01000100       Q    01010001
E    01000101       R    01010010
F    01000110       S    01010011
G    01000111       T    01010100
H    01001000       U    01010101
I    01001001       V    01010110
J    01001010       W    01010111
K    01001011       X    01011000
L    01001100       Y    01011001
M    01001101       Z    01011010



ALPHABET IN (8 bit) BINARY, LOWER CASE

a    01100001       n    01101110
b    01100010       o    01101111
c    01100011       p    01110000
d    01100100       q    01110001
e    01100101       r    01110010
f    01100110       s    01110011
g    01100111       t    01110100
h    01101000       u    01110101
i    01101001       v    01110110
j    01101010       w    01110111
k    01101011       x    01111000
l    01101100       y    01111001
m    01101101       z    01111010

You already have an Array variable named mat1[] which holds your string letters and what I propose is to make it a two dimensional array, 1 column to hold the letter and a 2nd column to hold the binary translation for that letter. Once you have the translation established you can convert back and forth from letter string to Binary and Binary to letter string. Here is the code (just copy/paste and run):

public class CharacterTranslation {

    public static void main(String[] args) {
        // Translation Table made from a two dimensional Array:
        String[][] mat1 = {{"A","00"},{"T","01"},{"G","10"},{"C","11"}};
        String input = "GCAT";

        System.out.println("Original Input: " + input);

        // Convert each character within the supplied input string
        // to our binary character translation.
        String translation = "";
        for (int i = 0; i < input.length(); i++) {
            String c = Character.toString(input.charAt(i)); 
            for (int j = 0; j < mat1.length; j++) {
                if (mat1[j][0].equals(c)) { translation+= mat1[j][1]; break; }
            }
        }
        // Display the translation in output console (pane).
        System.out.println("Convert To Binary Translation: " + translation);

        // Now, convert the binary translation back to our 
        // original character input. Note: this only works
        // if the binary translation is only 2 bits for any 
        // character.
        String origInput = "";
        for (int i = 0; i < translation.length(); i+= 2) {
            String b = translation.substring(i, i+2);
            for (int j = 0; j < mat1.length; j++) {
                if (mat1[j][1].equals(b)) { origInput+= mat1[j][0]; break; }
            }
        }

        // Display the converted binary translation back to 
        // it original characters.
        System.out.println("Convert Back To Original Input: " + origInput);
    }

}
DevilsHnd - 退職した
  • 8,739
  • 2
  • 19
  • 22
  • You know what I did I have convert the string to the 4 letters which are ACGT – Sam Dec 10 '15 at 17:01
  • and it works but I need it to revers it back from AGCT to string – Sam Dec 10 '15 at 17:03
  • The code I provided does exactly that Sam. The first 'for loop' pair converts each character to its translated binary. The second 'for loop' pair converts the appended binary string that was created back to its original character (letter) string. Your are going to have to let me know exactly what you are calling a string. – DevilsHnd - 退職した Dec 11 '15 at 00:53
  • Thanks a lot DevisHud I haven't test it yet cos I am on Travelling I just have another question after I did the first step which is convert any characters to AGCT how can I put the process of the jtextfield form automatically convert to AGCT like for example I have written London in the text field form I want this string to convert it to their corresponding of ACGT letters what is the process code to do this. – Sam Dec 11 '15 at 11:44
  • Hi Devi I have checked the code you sent to me you understand me wrong, my question is the GCTAAACCTTGG they are sequence of strings or numbers which is the outcomes from the value of binaries as A is 00 T 01 G10 and C 00 so when I connect to the database data this data could any word which then convert it to ASCII and then binary and finally it converts to these sequences of GGCCTTAATACG and I want these sequences reverse back to the original word how can I do this – Sam Dec 11 '15 at 19:18
  • Sam, I hat to say this but the more information you provide the more confused I get. Can you please give me visual examples of what you are trying to accomplish. Are you talking about: the Word from Database is "HELLO": To ASCII is 7269767679 then to Binary is 0100100001000101010011000100110001001111 and then the binary value back to the word from database: "HELLO"? Each character or number can not relate to just two digits of 0 and 1. – DevilsHnd - 退職した Dec 11 '15 at 22:57
  • Hi DEvi of course the way is like this the Word from Database is "HELLO": To ASCII is 7269767679 then to Binary is 0100100001000101010011000100110001001111 and then the binary to the AGCTCCCTTAA as each two binary digits give us the letter of its value in terms of 00=A 01=T 10=G and 11=C this is the result of it I did this way and it works but I have tried to copy the codes here it said its long but it won't accept to submit it in this site, therefore I want to do the way back to the word from the AGCTCCCTTAA to binary then to Ascii then to Hello, thanks – Sam Dec 12 '15 at 08:26
  • Uhhhh...I see what you are talking about now. Okay Sam, I'll get back to you in a few moments. – DevilsHnd - 退職した Dec 12 '15 at 20:55
  • See the new post. I provided the code required to carry out the task. I left the old post since someone may find that useful as well. – DevilsHnd - 退職した Dec 12 '15 at 22:57
  • @DevilsHud I have one last question so after this I won't ask again my question is how can I code the java database not to allow more than one user access to same username so I want to allow only one user can access and block second access to same username and password at same time. please this is last question and I appreciate your help thanks – Sam Jan 10 '16 at 08:52
  • Again, not enough information. This is called Exclusive Access and it depends upon the the database type itself. Is it SQL Server, MYSQL, SQLlite, Derby, MS ACCESS, ORACLE, .....???. Google that very same question for your specific database type and you will be filled with a vast amount of information about it. Again, ask this question in a new StackOverflow post so that others may benefit from the answer you receive. – DevilsHnd - 退職した Jan 10 '16 at 15:20
  • @DevilsHud String sql="select * from security where user_key=?"; try{ PreparedStatement ps= conn.prepareStatement(sql); ps.setString(1, jTextField1.getText()); ResultSet rs=ps.executeQuery(); if (rs.next()){ Admin ad = new Admin(); ad.show(); – Sam Jan 10 '16 at 15:33
  • I have found this from google but not in java if(//user is valid and validated from database etc...) { session.setAttribute("UserContext", dto); //this will invoke valueBound method of LoginDto. if(dto.isAlreadyLoggedIn())session.removeAttribute("UserContext"); //this will invoke valueUnbound method of LoginDto throw new MyCustomException("You are already logged in from a different session. Please logout first."); }}else {session.setAttribute("UserContext", null);} i need it like this but in java database sql – Sam Jan 10 '16 at 15:43
  • @DevilsHud protected static void OnRowUpdated(object sender, SqlRowUpdatedEventArgs args) { if (args.RecordsAffected == 0) { args.Row.RowError = "Optimistic Concurrency Violation Encountered"; args.Status = UpdateStatus.SkipCurrentRow; } } // this codes in C# database can you do like this function in java and the previous one is in Visual Basic please – Sam Jan 11 '16 at 18:41
  • @DevilsHud I have asked and no one can answer it could you see any solution in java for concurrent access and this is the link where I asked in codes and details http://stackoverflow.com/questions/34693010/deny-access-to-specific-account-in-database-more-than-one?noredirect=1#comment57136473_34693010 – Sam Jan 18 '16 at 06:04
0

Based from your last comment Sam I believe I now understand what you require and as you can see in the code below it is relatively easy to accomplish providing specific rules are followed.

One such rule is that the Binary value for each ASCII character must be 8 bits. Because lower ASCII (0 to 127) only truly represents a 7 bit binary value (ie: A = 1000001 and z = 1111010) we must ensure that a 0 is padded to the left most end of the binary value so as to produce a definite 8 bit binary number. We need to do this because our ACGT translation requires two binary digits for each character (ie: A = 00, C = 11, G = 10, T = 01) and therefore all binary values (appended or not) must be dividable by 2 and have no remainder. If we left everything as 7 bit binary values then this can not be accomplish. Now, knowing that we need to append a 0 to the left most of each ASCII binary value to establish 8 bit we will find that the ACGT string will always start with either a 'T' or an 'A'. The ACGT string will never start with a 'C' or a 'G'. If this is unacceptable then the ACGT character to Binary translation must change or the Padding to our ASCII binary value must change. It should be the translation that changes because if a change is made to the ASCII Binary value then it will be a misrepresentation of the ASCII Binary which is not good.

Another rule is that the ACGT Character to Binary Translation always remains the same. It never changes throughout processing.

The new code I provide below carries out the task you described within your last comment. I will leave the previous code from my previous post as it is since someone may find that useful as well.

In this new code I have used a Scanner to receive input from a User for testing purposes. I understand that you will be retrieving strings from a database and I will leave that up to you as to how you will implement that to the code since placing the two conversional sections of this code into methods would be the best way to go here.

As with just about anything with Java, there are about 12 ways to do anything however I particularly used 'for loops' to process things here since it's the easiest to follow in my opinion. You can optimize this code any way you see fit once you have it working exactly the way way you want.

Here is the code (copy/paste/run):

import java.util.Arrays;
import java.util.Scanner;

public class CharacterTranslation {

    public static void main(String[] args) {
        // Get Input from User...
        Scanner in = new Scanner (System.in);
        System.out.println("***  CONVERT FROM STRING TO ASCII TO BINARY TO ACGT  ***\n");
        System.out.println("Please enter a String to Convert to ACGT:");
        String inputString = in.nextLine();   

        // Declare and initialize required variables...
        int[] inputAscii = new int[inputString.length()];
        String[] inputBinary = new String[inputString.length()];
        // Translation Table made from a two dimensional Array:
        String[][] ACGTtranslation = {{"A","00"},{"T","01"},{"G","10"},{"C","11"}};

        // ------------------------------------------------
        // --------  CONVERT FROM STRING TO ACGT ----------
        // ------------------------------------------------

        //Convert the input string into ASCII numbers...
        for (int i = 0; i < inputString.length(); i++) {
            char character = inputString.charAt(i); 
            inputAscii[i] = (int) character; 
        }

        System.out.println("Conversion To ASCII:  " + Arrays.toString(inputAscii)
                           .replace("[","").replace("]",""));

        //Convert the ASCII Numbers to 8 bit Binary numbers...
        for (int i = 0; i < inputAscii.length; i++) {
            String bs =  String.valueOf(Integer.toBinaryString(0x100 + 
                         inputAscii[i]).substring(2));
            // Pad the left end of the binary number with 0 should
            // it not be 8 bits. ASCII Charcters will only produce
            // 7 bit binary. We must have 8 bits to acquire a even
            // number of digit pairs for our ACGT convertion.
            while (bs.length() < 8) { bs = "0" + bs; }
            inputBinary[i] = bs; 
        }

        System.out.println("Conversion To 8bit Binary:  " + Arrays.toString(inputBinary)
                           .replace("[","").replace("]",""));

        //Convert the Binary String to ACGT format based from 
        // our translational Two Dimensional String Array.
        // First we append all the binary data together to form
        // a single string of binary numbers then starting from 
        // the left we break off 2 binary digits at a time to 
        // convert to our ACGT string format.

        // Convert the inputBinary Array to a single binary String...
        String binaryString = "";
        for (int i = 0; i < inputBinary.length; i++) {
            binaryString+= String.valueOf(inputBinary[i]);
        }
        // Convert the Binary String to ACGT...
        String ACGTstring = "";
        for (int i = 0; i < binaryString.length(); i+= 2) {
            String tmp = binaryString.substring(i, i+2);
            for (int j = 0; j < ACGTtranslation.length; j++) {
                if (tmp.equals(ACGTtranslation[j][1])) { 
                    ACGTstring+= ACGTtranslation[j][0];
                }            
            }
        }

        System.out.println("The ACGT Translation String for the Word '" +
                           inputString + "' is:  " + ACGTstring + "\n");


        // ------------------------------------------------
        // -----  CONVERT FROM ACGT BACK TO STRING --------
        // ------------------------------------------------

        System.out.println("***  CONVERT FROM ACGT (" + ACGTstring + 
                           "' TO BINARY TO ASCII TO STRING  ***\n");
        System.out.println("Press ENTER Key To Continue...");
        String tmp = in.nextLine();

        // Convert ACGT back to 8bit Binary...

        String translation = "";
        for (int i = 0; i < ACGTstring.length(); i++) {
            String c = Character.toString(ACGTstring.charAt(i)); 
            for (int j = 0; j < ACGTtranslation.length; j++) {
                if (ACGTtranslation[j][0].equals(c)) { translation+= ACGTtranslation[j][1]; break; }
            }
        }

        // We divide the translation String by 8 so as to get 
        // the total number of 8 bit binary numbers that would
        // be contained within that ACGT String. We then reinitialize
        // our inputBinary Array to hold that many binary numbers.
        inputBinary = new String[translation.length() / 8];
        int cntr = 0;
        for (int i = 0; i < translation.length(); i+= 8) {
            inputBinary[cntr] = translation.substring(i, i+8);
            cntr++;
        }
        System.out.println("Conversion from ACGT To 8bit Binary:  " + 
                           Arrays.toString(inputBinary).replace("[","")
                           .replace("]",""));

        //Convert 8bit Binary To ASCII...
        inputAscii = new int[inputBinary.length];
        for (int i = 0; i < inputBinary.length; i++) {
            inputAscii[i] = Integer.parseInt(inputBinary[i], 2);
        }

        System.out.println("Conversion from Binary To ASCII:  " + Arrays.toString(inputAscii)
                           .replace("[","").replace("]",""));

        // Convert ASCII to Character String...
        inputString = "";
        for (int i = 0; i < inputAscii.length; i++) {
            inputString+= Character.toString ((char) inputAscii[i]);
        }

        System.out.println("Conversion from ASCII to Character String:  " + inputString);
        System.out.println("**  Process Complete  ***");
    }
} 

EDIT:

I want to add that I have supplied a bit of a fib within the text. Most characters used within the ASCII character set (which are used for strings - ASCII 32 to 127) are represented by a 7 bit Binary value however, Characters within the Upper ASCII character set (128 to 255) are represented with an actual 8 bit binary value. The code provided takes this into account. I have edited my answer to accommodate this.

DevilsHnd - 退職した
  • 8,739
  • 2
  • 19
  • 22
  • Hi Devi Thanks this is the answer thanks a lot and now I want to connect it to the database so when there is a data in the database it show us the process in the jTextField with two buttons as first button is for the first process from string to the sequence translated then the second button the way back from the sequence to the string data, how can I send to you my codes as here this site shows lots of incomplete code while in my system they working fine just to show you, also can I do the TextField translate these string to sequences suck as (TAGCGGGTTT) automatically or no. – Sam Dec 13 '15 at 15:35
  • Place the section of code under the title: "Convert from String to ACGT" into a method, let's say: stringToACGT(String inputString) then from the actionPerformed event for one of your buttons you call this method. The same would apply for the code section titled: "Convert From ACGT Back To String". Create a method acgtToString(String inputString) and call that method from the actionPerformed event of your other button. And Yes....you can translate a string such as TAGCGGGTTT from a JTextField as well if you place the code into methods. It will convert it to a String based on the translation. – DevilsHnd - 退職した Dec 13 '15 at 15:43
  • Hi Devi Thanks for your help I just want to see how can I code the jTextField convert automatically to a sequence of AAGAGC for example when I put any character such as any from A to Z or number it change in the text field to sequence like if I typed Hello in the text field it show us its value sequence ACCGGTTAAACA straight away in the textfield – Sam Dec 14 '15 at 17:02
  • *** CONVERT FROM ACGT (null' TO BINARY TO ASCII TO STRING *** Press ENTER Key To Continue... Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at desktopapplication3.NewJFrame.jButton3ActionPerformed(NewJFrame.java:323) at desktopapplication3.NewJFrame.access$200(NewJFrame.java:19) at desktopapplication3.NewJFrame$3.actionPerformed(NewJFrame.java:67) at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995) at I get this error when convert from the reverse button seq to string – Sam Dec 15 '15 at 19:10
0

For what you really want to do Sam, we only need one button. We can make it act like a toggle button between two different functions. One Button and One Text Field. This is pretty basic stuff.

The translation table 2 Dimensional Array should be placed under the constructor for your GUI class so that it's available to all methods, something like this:

public class MyGUIClassName??? extends javax.swing.JFrame {
    String[][] ACGTtranslation = {{"A","00"},{"T","01"},{"G","10"},{"C","11"}};
    ..............................
    ..............................
    ..............................
}

Then your jButton3 ActionPerformed event could look somethIng like:

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) { 
    // Skip this event if there is nothing contained
    // within jTextField1.
    if (jTextField1.getText().isEmpty()) { return; }

    // Get the current text in jButton3.
    String buttonText = jButton3.getText();

    // If the button text reads "Convert To ACGT" then...
    if ("Convert To ACGT".equals(buttonText)) {
        // change the button text to "Convert To String".
        jButton3.setText("Convert To String");
        // Convert the string from database now contained in jTextField1
        // to ACGT format and place that new ACGT into the same JTextfield.
        // We use the StringToACGT() method for this.
        jTextField1.SetText(StringToACGT(jTextField1.getText());
    }

    // The button text must be "Convert To String"...
    else {
        // so let's change the button text to now be "Convert To ACGT"
        // again.
        jButton3.setText("Convert To ACGT");
        // Take the ACGT string now contained within jTextField1
        // from the first button click and convert it back to its 
        // original String format. We use the ACGTtoString() method
        // for this.
        jTextField1.SetText(ACGTtoString(jTextField1.getText());
    } 
}

And here are the methods you also place into your GUI class:

// CONVERT A STRING TO ACGT FORMAT
public static String StringToACGT(String inputString) {
    // Make sure the input string contains something.
    if ("".equals(inputString)) { return ""; }

    // Declare and initialize required variables...
    int[] inputAscii = new int[inputString.length()];
    String[] inputBinary = new String[inputString.length()];

    //Convert the input string into ASCII numbers...
    for (int i = 0; i < inputString.length(); i++) {
        char character = inputString.charAt(i); 
        inputAscii[i] = (int) character; 
    }

    //Convert the ASCII Numbers to 8 bit Binary numbers...
    for (int i = 0; i < inputAscii.length; i++) {
        String bs =  String.valueOf(Integer.toBinaryString(0x100 + 
                     inputAscii[i]).substring(2));
        // Pad the left end of the binary number with 0 should
        // it not be 8 bits. ASCII Charcters will only produce
        // 7 bit binary. We must have 8 bits to acquire a even
        // number of digit pairs for our ACGT convertion.
        while (bs.length() < 8) { bs = "0" + bs; }
        inputBinary[i] = bs; 
    }

    //Convert the Binary String to ACGT format based from 
    // our translational Two Dimensional String Array.
    // First we append all the binary data together to form
    // a single string of binary numbers then starting from 
    // the left we break off 2 binary digits at a time to 
    // convert to our ACGT string format.

    // Convert the inputBinary Array to a single binary String...
    String binaryString = "";
    for (int i = 0; i < inputBinary.length; i++) {
        binaryString+= String.valueOf(inputBinary[i]);
    }
    // Convert the Binary String to ACGT...
    String ACGTstring = "";
    for (int i = 0; i < binaryString.length(); i+= 2) {
        String tmp = binaryString.substring(i, i+2);
        for (int j = 0; j < ACGTtranslation.length; j++) {
            if (tmp.equals(ACGTtranslation[j][1])) { 
                ACGTstring+= ACGTtranslation[j][0];
            }            
        }
    }
    return ACGTstring;
}


// CONVERT A ACGT STRING BACK TO ITS ORIGINAL STRING STATE.    
public static String ACGTtoString(String inputString) {
    // Make sure the input string contains something.
    if ("".equals(inputString)) { return ""; }
    String ACGTstring = inputString;
    // Declare and initialize required variables...
    int[] inputAscii = new int[inputString.length()];
    String[] inputBinary = new String[inputString.length()];

    // Convert ACGT back to 8bit Binary...
    String translation = "";
    for (int i = 0; i < ACGTstring.length(); i++) {
        String c = Character.toString(ACGTstring.charAt(i)); 
        for (int j = 0; j < ACGTtranslation.length; j++) {
            if (ACGTtranslation[j][0].equals(c)) { translation+= ACGTtranslation[j][1]; break; }
        }
    }

    // We divide the translation String by 8 so as to get 
    // the total number of 8 bit binary numbers that would
    // be contained within that ACGT String. We then reinitialize
    // our inputBinary Array to hold that many binary numbers.
    inputBinary = new String[translation.length() / 8];
    int cntr = 0;
    for (int i = 0; i < translation.length(); i+= 8) {
        inputBinary[cntr] = translation.substring(i, i+8);
        cntr++;
    }

    //Convert 8bit Binary To ASCII...
    inputAscii = new int[inputBinary.length];
    for (int i = 0; i < inputBinary.length; i++) {
        inputAscii[i] = Integer.parseInt(inputBinary[i], 2);
    }

    // Convert ASCII to Character String...
    inputString = "";
    for (int i = 0; i < inputAscii.length; i++) {
        inputString+= Character.toString ((char) inputAscii[i]);
    }

    return inputString;
}

Like I said earlier Sam, this is pretty basic material and you should already have a very good handle onto the Java programming language to get to this point, especially if you are actually retrieving the data to convert from a Database. My job here is Complete. :o) I hope this has helped you (and others) to obtain your goals.

DevilsHnd - 退職した
  • 8,739
  • 2
  • 19
  • 22
  • // Convert the Binary String to ACGT... String ACGTstring = ""; for (int i = 0; i < binaryString.length(); i+= 2) { String tmp = binaryString.substring(i, i+2); for (int j = 0; j < ACGTtranslation.length; j++) { if (tmp.equals(ACGTtranslation[j][1])) { ACGTstring+= ACGTtranslation[j][0]; } } } return ACGTstring; } the error appears here it said non-static variable AGCTtranslation cannot be referenced from a static context – Sam Dec 19 '15 at 20:35
  • When you declare your ACGTtranslation[] Array be sure to declare it as this in your class constructor: private static String[][] ACGTtranslation = {{"A","00"},{"T","01"},{"G","10"},{"C","11"}}; It must be declared as static since the methods using it are static. – DevilsHnd - 退職した Dec 19 '15 at 22:34
  • thanks it works now I just want to save the encrypted data converted to GCTA to the database and can I save each inputted to the database through the jTextArea or jTextField so can the database do this or not when input string data and saved it as GCTA or not thanks – Sam Dec 21 '15 at 14:23
  • Yes you can. Since the original data to convert would have come from a string field within the database and it is remains a string once converted it can be placed back into the database. You can even do the conversion to the database field without a GUI (background DB wide) but it is best to be done as data is supplied saved to DB as encrypted ACGT. This would be an entirely different question. Create a new SO Question. – DevilsHnd - 退職した Dec 21 '15 at 20:07
  • Thanks I just want typing the string in jtextfield and it shows the conversion AGCT instead when typing letter or number and then this conversion want to save it in the database as GCTA and when I retrieve it, when I input the string, or you mean the database itself need different coding to convert the string – Sam Dec 22 '15 at 20:24
  • Nothing needs to be done Sam. whatever is in the JTextField will be considered a String so you can just save it directly to your DB. – DevilsHnd - 退職した Dec 22 '15 at 23:39
  • what is the code for saving directly to the database so I have added the entityManager, query and list to the jFrame form and I am trying to connect the field of the table to get the connection and then input the data to the database – Sam Dec 24 '15 at 12:40
  • Post a new question in this forum regarding this particular issue. It does not pertain the current question at hand. As a quick tip though: You simply create a SQL query string utilizing the sql UPDATE statement and run that against your connected database table for the row the data was retrieved from. – DevilsHnd - 退職した Dec 24 '15 at 12:51
  • try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection connection = DriverManager.getConnection("jdbc:derby://localhost:1527/DNA;) PreparedStatement name = connection.prepareStatement("Select Username from userprofile");ResultSetresult=name.executeQuery();}catch (ClassNotFoundException e);} try {rs1 = Connection.SQLSelect("select Username from userprofile");} catch (ClassNotFoundException ex) { Logger.getLogger(test.class.getName()); } while (rs1.next()){s1 = rs1.getString("Username"); – Sam Dec 26 '15 at 12:01
  • this is the database I have created and I want to make a connection to it by adding the save button in order to save the conversion to AGCT in the database so as you said I can save the conversion to database field how can i do it – Sam Dec 26 '15 at 12:44
  • I have tried to post my codes but i won't post here as it said code is not in the right format so what I have to do – Sam Dec 28 '15 at 10:16
  • You are abusing the forum here. As I have already said twice before: Start a new thread regarding your new problem. The question asked in this thread has been answered! Any further comments here regarding your new problem is pointless! – DevilsHnd - 退職した Dec 29 '15 at 01:09
  • Hi Dev sorry about this i just have the database and the save button to it which is for saving the converted data ACAGTTTT to the database from the jTextArea after conversion. please – Sam Dec 29 '15 at 12:07
  • private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { connection conn = new connection(); conn.connect(); String name = String.valueOf(jTextField1.getText()); boolean b=false; try { conn.SQLUpdate( "INSERT INTO profile (username) "+ "VALUES ('" + jTextField1.getText() + "')" ); JOptionPane.showMessageDialog(null,"Success"); jTextField1.setText(); this.dispose(); }catch(SQLException e) {System.out.print(e); } } – Sam Dec 30 '15 at 12:53