+5 votes
by (100 points)

i get the error message in the screenshot image i have added when i try to update an existing field in the database what would be the problem

private void cmdUpdateMouseClicked(java.awt.event.MouseEvent evt) {                                       
   String sql="UPDATE std set ADM_NO=?,Form=?,Student=?,Parent=?,Contact=?";


    try {
       ps=conn.prepareStatement(sql);
              ps.setString(1, txtadm.getText());
              ps.setString(2, txtform.getText());
              ps.setString(3, txtsname.getText());
               ps.setString(4, txtpname.getText());
              ps.setString(5, txtmobileno.getText());


          ps.executeUpdate();

error screenshot

9 Answers

+25 votes
by (100 points)

You miss WHERE clause in your SQL, it updates whole table. For update it generally requires primary key e.g. WHERE primary_key_column=id

+24 votes
by (100 points)

it looks that, you are trying to set a value to a field with is PRIMARY KEY what does mean that it could not have duplicated value, should be unique.

+20 votes
by (100 points)

It looks like your code is trying to update every row in that table:

UPDATE std set ADM_NO=?,Form=?,Student=?,Parent=?,Contact=?

You need to target the rows you want to update by using a where clause. I guess the ADM_NO is the primary key and the query is trying to update all rows to have the same primary key.

+20 votes
by (100 points)

You are trying to update the primary key of the table to a value that already exists.

As you update without a WHERE clause this means you apply the update on all rows on the table and that does not work because you will set the primary key again and again to the same value.

Find out what is your primary key. Not sure what tool you use to administer the mySQL table but you could use

SHOW COLUMNS FROM std

I guess you primary key is ADM_NO

So you maybe need to code something like:

...
String sql="UPDATE std set Form=?,Student=?,Parent=?,Contact=? WHERE  ADM_NO=?";
...
          ps.setString(1, txtform.getText());
          ps.setString(2, txtsname.getText());
          ps.setString(3, txtpname.getText());
          ps.setString(4, txtmobileno.getText());
          ps.setString(5, txtadm.getText());

Just a guess

+14 votes
by (100 points)

Hello there is no "Where" clause this is too obvious there is a unique key on the file.

+10 votes
by (100 points)

You are using float as well as margin:0 auto replace the main css with the following;

.main{
 float:left;
 width:50%;
 text-align: center;
 border:10px solid white;
 width:306px;
 height:306px;
 box-shadow: 0px 0px 25px black;
 overflow: hidden;
 }
+10 votes
by (100 points)

This one was tricky. It took some thinking.

declare module yargs {
    export interface Yargs {
        argv: string[];
        (input: string[]): Yargs;
        count(option: string): Yargs;
        alias(shrt: string, lng: string): Yargs;
    }
}

declare module "yargs" {
    var y: yargs.Yargs;
    export = y;
}
+5 votes
by (100 points)

I'll assume you got nodejs from the chris-lea ppa.

try sudo npm cache clear

+1 vote
by (100 points)

Clean data by use of replaceAll :

val counts = file.flatMap(line => line.trim.toLowerCase.split(" ").replaceAll("[$,?+.;:\'s\\W\\d]", ""));

sort by value in scala API:

.map(item => item.swap) // interchanges position of entries in each tuple
.sortByKey(true, 1) // 1st arg configures ascending sort, 2nd arg configures one task
.map(item => item.swap)

sort by value in python API:

.map(lambda (a, b): (b, a)) \
.sortByKey(1, 1) \ # 1st arg configures ascending sort, 2nd configures 1 task
.map(lambda (a, b): (b, a))

Code should look like this ( you may see syntax error, please fix if any ):

val file = sc.textFile("hdfs://localhost:9000/Peter")
val counts = file.flatMap(line => line.trim.toLowerCase.split(" ").replaceAll("[$,?+.;:\'s\\W\\d]", ""))
                 .map(p => (p,1))
                 .reduceByKey(_+_)
                 .map(rec => rec.swap)
                 .sortByKey(true, 1)
                 .map(rec => rec.swap)

counts.saveAsTextFile("Peter_SortedOutput6")

see scala_regular_expressions - for what [\\W] or [\\d] or [;:',.?] mean.

No related questions found

...