Solved

java.sql.SQLException : No resultset was produced

Posted on 2004-04-30
17
6,721 Views
Last Modified: 2012-06-27
i m inserting a tuple in my oracle database connected through jdbc odbc driver. now when i insert it gives me java.sql.SQLException : No ResultSet was produced.

now for insert query no result set is produced. how to solve this

please reply soon......
0
Comment
Question by:kashish_18_2003
  • 11
  • 5
17 Comments
 
LVL 4

Expert Comment

by:91mustang
ID: 10961579
post the problem code please
0
 
LVL 4

Expert Comment

by:91mustang
ID: 10961628
>>>now for insert query no result set is produced. how to solve this

rs.execute(query);

instead of

rs.executeQuery(query)
0
 
LVL 7

Expert Comment

by:mark-b
ID: 10961900
For direct inserts you should most likely be using executeUpdate() on a Statement:

Ex:

// Returns num rows affected (number of inserts, updates or deletes)
int numResults = stmt.executeUpdate( query );

Or, if you are expecting result sets (doesn't happen often on inserts)  then you can use execute:

boolean hasResultSets = stmt.execute( query );
int numResults = 0;

if ( !hasResultsSets ) {
  numberResults = stmt.getUpateCount();
} else {
   while ( stmt.getMoreResults() ) {
       ResultSet rs = stmt. getResultSet();
       // do something with these result sets
  }
}

-Mark
0
 

Author Comment

by:kashish_18_2003
ID: 10968675
//its a long code but i hope it helps

//Jpeg_Classifier.java

//class for classifying jpeg and png images

import java.sql.*;
import java.awt.*;
import java.awt.image.*;
import java.io.*;
import java.util.*;
import javax.imageio.*;
import javax.imageio.stream.*;


//data structure for pixel properties
class PixelProperties{
        public int brightness,red,green,blue;
        public PixelProperties(){}
}

//main class
public class Jpeg_Classifier{
        //properties of image
      protected int width, height,no_red,no_green,no_blue,used;
       
      protected int histogram[]=new int[256];
        protected int reg_code[];
        protected PixelProperties pixel[][];
             String imageName;
      BufferedImage bufImage;
      Image image;
      //for creating connection and querying
      DBMSConnection dc;
      Connection con;
      Statement statement;
      String queryString;
        public Jpeg_Classifier(String filename,String absfileName)throws IOException{
              try{

                System.out.println("in jpeg classifier:"+filename);
                ImageReader imageReader;
                used=0;
                // Extract the file name suffix.
                String ext = filename.substring(filename.indexOf('.')+1);
                        // Create a file object for the file name.
                File fileImage = new File(absfileName);
                        // Get a list of ImageReaders that claim
                        // to be able to decode this image file
                        // based on the file name suffix.
                Iterator imageReaders = ImageIO.getImageReadersBySuffix(ext);
                        // Grab the first ImageReader in the list.
                if(imageReaders.hasNext())
                        imageReader = (ImageReader)imageReaders.next();
                        // If we get here we cannot decode the image.
                else throw new IIOException("Unsupported image format");
                        // Create a file input stream object to
                        // read the image date.
            
                FileImageInputStream imageInputStream =
                new FileImageInputStream(fileImage);
                        // Tell the ImageReader object to read data
                        // from our file input stream object.
                imageReader.setInput(imageInputStream);
                        // Get the width and height of the image.
                width = imageReader.getWidth(0);
                height = imageReader.getHeight(0);
            image = imageReader.read(0);
                bufImage = imageReader.read(0);
            imageInputStream.close();
            imageName=absfileName;
            // Create a file object for the file name.
            File newfileImage = new File("c:\\j2sdk1.4.1_02\\bin\\miner_images\\"+filename);
            // Get a list of ImageWriters that claim to
            // be able to encode images in the specified
            // image file format based on the file name
            // suffix.
            Iterator imageWriters = ImageIO.getImageWritersBySuffix(ext);
            ImageWriter imageWriter;
            // Grab the first ImageWriter in the list.
            if (imageWriters.hasNext())
            imageWriter = (ImageWriter)imageWriters.next();
            // If we get here we cannot encode the image.
            else throw new IIOException
            ("Unsupported image format");
            // Create a file output stream object to
            // write the image data.
            FileImageOutputStream imageOutputStream= new FileImageOutputStream(newfileImage);
            // Tell the ImageWriter to use our file
            // output stream object.
            imageWriter.setOutput(imageOutputStream);
            // The ImageWriter.write() method expects a
            // BufferedImage. Convert our 'samples' array
            // into a BufferedImage.
            // Encode the image to the output file.
            imageWriter.write(bufImage);
            imageOutputStream.close();

                no_red=0;no_green=0;no_blue=0;
                reg_code=new int[width*height+1];
                System.out.println(height+" "+width);
                pixel = new PixelProperties[height][width];
            //allocate memory for each pixel          
            for(int i=0;i<height;i++)
                  for(int j=0;j<width;j++)
                        pixel[i][j] = new PixelProperties();
                   
            try{
                  //establish connection with the database
                  dc=new DBMSConnection();
                  con=dc.getConnection();
                  statement=con.createStatement();
      
            }catch(Exception ex){

            }
                 Classify_By_Color();      //classify by color
             Classify_By_Brightness(); //by brightness
             
               }
               catch(Exception e){
                System.out.println("Exception in constructor of ImP"+e);
               }

      }
        private void Classify_By_Color()throws IOException{
              try{  
            //grab pixels
            PixelGrabber pg=new PixelGrabber(image,0,0,height,width,false);
                pg.grabPixels();
            //get color model of the image
                ColorModel cm=(ColorModel)pg.getColorModel();
                int Pixels[];
                Pixels=new int[height*width];
            
            int r,g,b;
                //get pixels
            Pixels=(int[])pg.getPixels();        
            //get rgb value for each pixel
                for(int row=0;row<height;row++)
                  for(int col=0;col<width;col++){
                r=(pixel[row][col]).red=cm.getRed(Pixels[row*width+col]);

                    g=(pixel[row][col]).green=cm.getGreen(Pixels[row*width+col]);
                    b=(pixel[row][col]).blue=cm.getBlue(Pixels[row*width+col]);
                  //find no. or pixel for each color
                    if(r>=g && r>=b) no_red++;
                    if(g>=r && g>=b) no_green++;
                    if(b>=r && b>=g) no_blue++;
                  }

            //determine class            
                System.out.println(no_red+" "+no_green+" "+no_blue);
                if(no_red >=no_green && no_red>=no_blue){
                        System.out.println("Red");
                  Insert_Color('R');
            }
                if(no_green >=no_red && no_green>=no_blue){
                        System.out.println("Green");
                  Insert_Color('G');
            }
                if(no_blue >=no_green && no_blue>=no_red){
                        System.out.println("Blue");
                  Insert_Color('B');
            }
             }
             catch(Exception e){
                System.out.println("Exception in Color Classifier"+e);
             }

      }      
      //Insert into database color value
      void Insert_Color(char color)throws SQLException{
            
            queryString="insert into color_classifier values('"+imageName+"','"+color+"')";      
            System.out.println(queryString);
            statement.executeQuery(queryString);      
            
      }
      //insert into database brightness value
      void Insert_Brightness(char brightness)throws SQLException{

            queryString="insert into brightness_classifier values('"+imageName+"','"+brightness+"')";                                          
            System.out.println(queryString);

            statement.executeQuery(queryString);      
            
      }



            
      private void Classify_By_Brightness()throws IOException{
              try{
                     // Get a raster object so we can extract the
                        // pixel data from the BufferedImage.
                WritableRaster wRaster = bufImage.getRaster();
                        // Create our 'samples' 2d-array.
                        // Extract the image data into our 'samples'
                        // array.
            int i,b;
            //initialize the histogram
                for(i=0;i<256;i++)
                        histogram[i]=0;
                //construct the histogram
            for (int row = 0; row < height; row++)
                  for (int col = 0; col < width; col++){
                        pixel[row][col].brightness = wRaster.getSample(col,row,0);
                        b=pixel[row][col].brightness;
                        histogram[b]++;
                  }
                int no_l=0,no_r=0;
            //getting the left and right side of project
                for(i=0;i<128;i++)
                        no_l+=histogram[i];
                for(i=128;i<256;i++)
                        no_r+=histogram[i];
                System.out.println(no_l+" "+no_r);
            //get the brightness class
                if(no_l<no_r){
                      System.out.println("LIGHT");
                  Insert_Brightness('L');
            }
                else if (no_l>no_r){
                  System.out.println("DARK");
                  Insert_Brightness('D');
            }

                else{
                        System.out.println("NIETHER LIGHT NOR DARK");
                  Insert_Brightness('E');
            }

            
             }
             catch(Exception e){
                System.out.println("Exception in Brightness Classifier"+e);
             }
        }
}









      
0
 
LVL 4

Expert Comment

by:91mustang
ID: 10968707
The problem is that you are using executeQuery() for an insert statement.  executeQuery()  is looking to return a resultset, but your query does not return one as it is only inserting. execute() returns nothing.executeUpdate() returns number of rows affected

Change both occurences of:

statement.executeQuery(queryString);    
to either (both will work):

statement.execute(queryString);    
or
int numResults = statement.executeUpdate( queryString );

0
 

Author Comment

by:kashish_18_2003
ID: 10968752
see i have another module with similar code now that works well, but this is not working, why

then even that shud not work

i mean its ridiculous

0
 
LVL 4

Expert Comment

by:91mustang
ID: 10968761
Are you positive that other module is sending inserts, not selects...
I would geuss that other module is sending selects

Post other module please,
0
 
LVL 4

Expert Comment

by:91mustang
ID: 10968764
have you tried my suggestions?
What happens when you replace the executeQuery() with execute() or executeUpdate()
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:kashish_18_2003
ID: 10972801
i did executeupdate and that works but the other module works well with executequery only.... the module is:

import java.awt.image.*;
import java.awt.*;
import java.io.*;
//import java.util.*;
import javax.imageio.*;
import javax.imageio.stream.*;
import java.sql.*;

class pix{
 int red,green,blue,regcode,brightness;
}

class RP{
 int h,w,ba;
}

public class BMP_Classifier{

        int height,width,used,histogram[],l_pixel,r_pixel,no_red,no_blue,no_green;
        Image img;
        pix p[][];
      DBMSConnection dc;
      Connection con;
      String queryString,imageUrl;
      Statement statement;
       //function to obtain the color of the region
        private int getRColor(int reg){
          for(int i=0;i<height;i++)
           for(int j=0;j<width;j++)
            if(p[i][j].regcode==reg){
             int r=p[i][j].red;
             int g=p[i][j].green;
             int b=p[i][j].blue;
             if(r>g&&r>b) return 1;
             if(g>r&&g>b) return 2;
             if(b>r&&b>g) return 3;
             if(r==g && g==b && r<20) return 0;
             if(r==g && g==b && r>200) return 4;
             if(r==g && r> b) return 5;
             if(r==b && r>g) return 6;
             if(g==b && g> r) return 7;
            }
            return -1;
       }
       //function to get the color name with respect to code
       private String getName(int code){
        if(code==0) return "Black";
        if(code==1) return "Red";
        if(code==2) return "Green";
        if(code==3) return "Blue";
        if(code==4) return "White";
        if(code==5) return "Yellow";
        if(code==6) return "Magenta";
        if(code==7) return "Cyan";
        return "";
       }


        //determine the perimeter of the region with code r
        protected int Perimeter(int r){
                int pe=0;
                for(int i=0;i<height;i++)
                 for(int j=0;j<width;j++){
                  int n=0;
                  if(p[i][j].regcode==r){         //for each pixel of the region
                   if(IsUL(i,j))                  //if upper left pixel exists
                    if(p[i-1][j-1].regcode!=r)   //and of different color
                        n++;                     //increment n
                   if(IsL(i,j))
                     if(p[i][j-1].regcode!=r)     //if left pixel
                        n++;
                   if(IsU(i,j))                  //upper pixel
                      if(p[i-1][j].regcode!=r)
                       n++;
                   if(IsUR(i,j))                 //upper right
                    if(p[i-1][j+1].regcode!=r)
                     n++;
                   if(IsD(i,j))                 //down pixel
                     if(p[i+1][j].regcode!=r)
                      n++;
                   if(IsDL(i,j))                //lower left
                     if(p[i+1][j-1].regcode!=r)
                       n++;
                   if(IsDR(i,j))                //lower right
                    if(p[i+1][j+1].regcode!=r)
                     n++;
                   if(IsR(i,j))                 //just right
                    if(p[i][j+1].regcode!=r)
                     n++;
                   if(n>=3)                     //if more than three pixel are of different color this is boundary pixel
                    pe++;            //add this to the no. of pixels in perimeter
                  }
                 }

                return pe;
        }


        //determine the area of the region
        protected int Area(int r){
                int a=0;
                for(int i=0;i<height;i++)
                  for(int j=0;j<width;j++)
                   if(p[i][j].regcode==r)   //simply count the no. of pixels in the region
                    a++;
                 return a;
        }


        //determine whether upper left pixel exists for (x,y)
        private boolean IsUL(int x,int y){
         if(x-1>=0 && y-1>=0 && x<height && y<width)
          return true;
         return false;
        }
        //determine whether upper pixel exists for (x,y)
        private boolean IsU(int x,int y){
         if(x-1>=0 && x<height && y<width)
          return true;
         return false;
        }
        //determine whether upper right pixel exists for (x,y)
        private boolean IsUR(int x,int y){
         if(x-1>=0 && y+1<width && x<height && y<width)
          return true;
         return false;
        }
        //determine whether left pixel exists for (x,y)
        private boolean IsL(int x,int y){
         if(y-1>=0 && x<height && y<width)
          return true;
         return false;
        }
        //determine whether right pixel exists for (x,y)
        private boolean IsR(int x,int y){
         if(y+1<width && x<height && y<width)
          return true;
         return false;
        }
        //determine whether lower left pixel exists for (x,y)
        private boolean IsDL(int x,int y){
         if(y-1>=0 && x+1<height && x<height && y<width)
          return true;
         return false;
        }
        //determine whether lower pixel exists for (x,y)
        private boolean IsD(int x,int y){
         if(x+1<height && x<height && y<width)
          return true;
         return false;
        }
        //determine whether lower right pixels exists for (x,y)
        private boolean IsDR(int x,int y){
         if(y+1<width && x+1<height && x<height && y<width)
          return true;
         return false;
        }

        //determine whether this pixel is not assigned a code
        private boolean IsEmpty(pix p){
         if(p.regcode==-1)
          return true;
         return false;
        }

        //for segmentation perform the merge operation
        private void Basic_Merge(){
         double heuristic;
         double dr,db,dg;

         //for each pixel
         for(int i=0;i<height;i++){
          for(int j=0;j<width;j++){
           if(IsUL(i,j)){
            dr=Math.pow(Math.abs(p[i-1][j-1].red-p[i][j].red),2);
            dg=Math.pow(Math.abs(p[i-1][j-1].green-p[i][j].green),2);
            db=Math.pow(Math.abs(p[i-1][j-1].blue-p[i][j].blue),2);
            heuristic=Math.sqrt((dr+db+dg)/3);   //determine root mean square value for rgb differences
            if(heuristic<=32)                   //if the heuristic value is less
             p[i][j].regcode=p[i-1][j-1].regcode;    //than 32 assign neighbor's code
            }
            if(IsU(i,j)){
            dr=Math.pow(Math.abs(p[i-1][j].red-p[i][j].red),2);
            dg=Math.pow(Math.abs(p[i-1][j].green-p[i][j].green),2);
            db=Math.pow(Math.abs(p[i-1][j].blue-p[i][j].blue),2);
            heuristic=Math.sqrt((dr+db+dg)/3);
             if(heuristic<=32)
              p[i][j].regcode=p[i-1][j].regcode;
            }
            if(IsUR(i,j)){
            dr=Math.pow(Math.abs(p[i-1][j+1].red-p[i][j].red),2);
            dg=Math.pow(Math.abs(p[i-1][j+1].green-p[i][j].green),2);
            db=Math.pow(Math.abs(p[i-1][j+1].blue-p[i][j].blue),2);
            heuristic=Math.sqrt((dr+db+dg)/3);
             if(heuristic<=32)
             p[i][j].regcode=p[i-1][j+1].regcode;
            }
            if(IsL(i,j)){
            dr=Math.pow(Math.abs(p[i][j-1].red-p[i][j].red),2);
            dg=Math.pow(Math.abs(p[i][j-1].green-p[i][j].green),2);
            db=Math.pow(Math.abs(p[i][j-1].blue-p[i][j].blue),2);
            heuristic=Math.sqrt((dr+db+dg)/3);
             if(heuristic<=32)
             p[i][j].regcode=p[i][j-1].regcode;
           }
           if(IsR(i,j)){
            dr=Math.pow(Math.abs(p[i][j+1].red-p[i][j].red),2);
            dg=Math.pow(Math.abs(p[i][j+1].green-p[i][j].green),2);
            db=Math.pow(Math.abs(p[i][j+1].blue-p[i][j].blue),2);
            heuristic=Math.sqrt((dr+db+dg)/3);
            if(heuristic<=32)
             p[i][j+1].regcode=p[i][j].regcode;
           }
           if(IsDL(i,j)){
            dr=Math.pow(Math.abs(p[i+1][j-1].red-p[i][j].red),2);
            dg=Math.pow(Math.abs(p[i+1][j-1].green-p[i][j].green),2);
            db=Math.pow(Math.abs(p[i+1][j-1].blue-p[i][j].blue),2);
            heuristic=Math.sqrt((dr+db+dg)/3);
            if(heuristic<=32)
             p[i+1][j-1].regcode=p[i][j].regcode;
           }
           if(IsD(i,j)){
            dr=Math.pow(Math.abs(p[i+1][j].red-p[i][j].red),2);
            dg=Math.pow(Math.abs(p[i+1][j].green-p[i][j].green),2);
            db=Math.pow(Math.abs(p[i+1][j].blue-p[i][j].blue),2);
            heuristic=Math.sqrt((dr+db+dg)/3);
            if(heuristic<=32)
             p[i+1][j].regcode=p[i][j].regcode;
           }
           if(IsDR(i,j)){
            dr=Math.pow(Math.abs(p[i+1][j+1].red-p[i][j].red),2);
            dg=Math.pow(Math.abs(p[i+1][j+1].green-p[i][j].green),2);
            db=Math.pow(Math.abs(p[i+1][j+1].blue-p[i][j].blue),2);
            heuristic=Math.sqrt((dr+db+dg)/3);
            if(heuristic<=32)
             p[i+1][j+1].regcode=p[i][j].regcode;
           }
           if(IsEmpty(p[i][j])){
            p[i][j].regcode=used;        //if unassigned, assign a new code
            used=used+1;
           }
          }
         }
        }
       


        protected RP Bounding_Area(int r){               //determine the properties of bounding rectangle
                boolean flag1=true,flag2=true;
                int lx,rx,ly,ry;
                RP r1= new RP();
                lx=rx=ly=ry=0;
                //scan from the top left and bottom right to get the first pixel
                for(int i=0;i<height;i++)              
                 for(int j=0;j<width;j++){
                        if(p[i][j].regcode==r&&flag1){
                           lx=i;
                           flag1=false;
                        }
                        if(p[height-i-1][width-j-1].regcode==r&&flag2){
                           rx=height-i-1;
                           flag2=false;
                        }
                        if(!flag1&&!flag2){
                           i=height;
                           j=width;
                        }
                 }
               flag1=flag2=true;
               //scan from left but this time in column order
               for(int j=0;j<width;j++)
                for(int i=0;i<height;i++){
                        if(p[i][j].regcode==r&&flag1){
                           ly=j;
                           flag1=false;
                        }
                        if(p[height-i-1][width-j-1].regcode==r&&flag2){
                           ry=width-j-1;
                           flag2=false;
                        }
                        if(!flag1&&!flag2){
                           i=height;
                           j=width;
                        }
                }

                r1.h=Math.abs(rx-lx);
                r1.w=Math.abs(ry-ly);
                r1.ba=(r1.h*r1.w);
                return r1;
        }

               
        //classify the image according to color, brightness and shape            
        BMP_Classifier(String fileName,String absfileName) throws Exception {
                        // Create a frame to display the image.
               
                try{
                             // Read the image from the file.
                       
                        classify(fileName,absfileName);
                                // Display the image.
                }
                catch (Exception e) {
                         System.out.println("Exception in main() "+e.toString());
                }
        }

        void classify(String fileName,String absfileName)throws Exception{

                        //load the bitmap in image object
                        img = utils.loadbitmap("",absfileName);
                        //get an image observer
                        iObserver imageObserver = new iObserver();
                  imageUrl=absfileName;
                      //get the height and width of the image
                        height = img.getHeight(imageObserver);
                        width = img.getWidth(imageObserver);
                  imageIO image_io=new imageIO();
                  int rgb[][][]=new int[height][width][4];
                  rgb=image_io.getImagePixels(img);

                        //convert the image to buffered image type
                  int imageType = BufferedImage.TYPE_BYTE_INDEXED;
                      BufferedImage newImage = new BufferedImage(width,height,imageType);
                      java.awt.Graphics2D destG = newImage.createGraphics();
                      destG.drawImage(img, 0, 0, null);

                        //get a raster object to scan the image
                        Raster raster=newImage.getRaster();

                        //create the pixel properties two d array
                        p=new pix[height][width];

                        for(int i=0;i<height;i++)
                        for(int j=0;j<width;j++){
                         p[i][j]=new pix();             //allocate memory for each pixel
                         p[i][j].regcode=-1;
                        }

                   
                        int Pixels[]=new int[height*width];
                        no_red=no_green=no_blue=0;
                        int r,g,b;

                        imageIO img_write=new imageIO();
                        img_write.saveImage(img_write.getImagePixels(img),"c:\\j2sdk1.4.1_02\\bin\\miner_images\\"+fileName);

                        l_pixel=r_pixel=0;
                        histogram=new int[256];

                        //initialize the histogram
                        for(int i=0;i<256;i++) histogram[i]=0;

                        //get the pixel properties
                        for(int row=0;row<height;row++)
                          for(int col=0;col<width;col++){

                            //obtain the brightness
                            p[row][col].brightness=raster.getSample(col,row,0);

                            //construct the histogram
                            histogram[p[row][col].brightness]++;

                            //get red, blue and green values
                            p[row][col].red=r=rgb[row][col][0];
                            p[row][col].green=g=rgb[row][col][1];
                            p[row][col].blue=b=rgb[row][col][2];

                            //determine no. of red, blue and green pixel
                            if(r>=g && r>=b) no_red++;
                            if(g>=r && g>=b) no_green++;
                            if(b>=r && b>=g) no_blue++;
                           }
                  try{
                  dc=new DBMSConnection();
                  con=dc.getConnection();
                  statement=con.createStatement();
                  }catch(Exception ex){}


                        classify_by_brightness();
                       
                        classify_by_color();
                        classify_by_shape();
                  con.close();      
        }

        void classify_by_shape(){
                        Basic_Merge();

                       
                       
                        for(int i=0;i<used;i++){
                               int a = Area(i);
                               if(a*100/(height*width)>1){
                               int p = Perimeter(i);
                               RP ba = Bounding_Area(i);
                               int c=1;
                               if(a>0)
                                c = p*p/a;
                               int re=0;
                               if(ba.ba>0)
                                re = a/ba.ba;
                               double radius=Math.sqrt(a/3.14);
                               float el=(float) (ba.h/ba.w);
                               int l2=ba.h/2;
                               int b2=ba.w/2;
                               double e=0,x,y,z;
                               x=l2*l2;
                               y=b2*b2;
                               if(l2>b2)
                                z=y/x;
                               else
                                z=x/y;
                               z=1-z;
                               e=Math.sqrt(z);
                               int code=getRColor(i);
                               double b_a=ba.ba;
                               double area=a;
                               double tri=b_a/area;
                               String color=getName(code);
                               
                  try{      
                               if((c==7 ||c==8) &&Math.abs(b2-radius)<=4 && tri<=1.2){
                               
                         Insert_Shape('C',color);
                        }      

                               else if(re==1 && el ==1){
                               
                         Insert_Shape('S',color);
                        }      
                          else if(tri >=1.92 && tri<=2.1){
                               
                         Insert_Shape('T',color);
                        }      
                               else if(re==1){
                               
                         Insert_Shape('R',color);
                        }                                 
                               else if(e>=0.8 && e<1 && tri>=1.1 && tri<=1.3){
                               
                         Insert_Shape('E',color);
                        }      

                  }catch(Exception ex){}
                               }


                        }


        }

      void Insert_Color(char color)throws SQLException{
            
            queryString="insert into color_classifier values('"+imageUrl+"','"+color+"')";      
            
            statement.executeQuery(queryString);      
            statement.executeQuery("commit");
      }

      void Insert_Brightness(char brightness)throws SQLException{

            queryString="insert into brightness_classifier values('"+imageUrl+"','"+brightness+"')";                                          

statement.executeQuery(queryString);      
            statement.executeQuery("commit");      
      }

      void Insert_Shape(char shape,String color)throws SQLException{
            queryString="insert into shape_classifier values('"+imageUrl+"','"+shape+"','"+color+"')";                                                
      statement.executeQuery(queryString);      
            statement.executeQuery("commit");      
      }

        void classify_by_color(){
            try{
                  
                  if(no_red >=no_green && no_red>=no_blue){
                               
                        Insert_Color('R');
                  }
                        if(no_green >=no_red && no_green>=no_blue){
                               
                        Insert_Color('G');
                  }
                        if(no_blue >=no_green && no_blue>=no_red){
                               
                        Insert_Color('B');
                  }

            }catch(Exception ex){}
        }
      
      

        void classify_by_brightness(){

                        //find no. of left pixels
                        for(int i=0;i<128;i++)
                         l_pixel+=histogram[i];
                        //find no. of right pixels
                        for(int i=128;i<256;i++)
                         r_pixel+=histogram[i];

                     
                       
                        //determine the brightness class of image
                        try{
                   if(l_pixel>r_pixel){
                         
                   Insert_Brightness('D');
                  }      
                        else if(l_pixel<r_pixel){
                         
                   Insert_Brightness('L');
                  }      

                        else{
                         
                   Insert_Brightness('E');
                   
                  }      
                  }catch(Exception ex){}

        }
           



}



0
 
LVL 4

Expert Comment

by:91mustang
ID: 10972832
Ahh Its starting to make sense now:

void Insert_Shape(char shape,String color)throws SQLException{
          queryString="insert into shape_classifier values('"+imageUrl+"','"+shape+"','"+color+"')";                                        
     statement.executeQuery(queryString);    
          statement.executeQuery("commit");    
     }

        void classify_by_color(){
          try{
               
               if(no_red >=no_green && no_red>=no_blue){
                               
                    Insert_Color('R');
               }
                        if(no_green >=no_red && no_green>=no_blue){
                               
                    Insert_Color('G');
               }
                        if(no_blue >=no_green && no_blue>=no_red){
                               
                    Insert_Color('B');
               }

          }catch(Exception ex){}
        }

Try adding an ex.printStackTrace() in the catch block. the same exception block is being thrown here, but the catch block is empty. You should try and avoid this, as it can make logic errors in programs very hard to debug.
0
 
LVL 4

Expert Comment

by:91mustang
ID: 10972891
Actually the empty ctch block is not the cause here. sorry. however you should still avois using empty catch's. I have no idea why one works and the other does not. Regardless, executeQuery should only be used with selects, not inserts
0
 
LVL 4

Expert Comment

by:91mustang
ID: 10972947
BTW, when i use your methods, the same exception is thrown...
0
 

Author Comment

by:kashish_18_2003
ID: 10980668
in both cases????????
0
 
LVL 4

Expert Comment

by:91mustang
ID: 10980720
yes, both cases produce same result
Strange that it works for you, its not supposed to work the way you have it.
I think if you use the correct methods, you programs will work better.
0
 

Author Comment

by:kashish_18_2003
ID: 10989470
well, the other program though dint throw exception but it was behaving a little unusual, in the way that once you perform one insertion through executequery the next insertquery was not being performed.....

so yaa.... both are not working well and i have changed both...
0
 
LVL 4

Accepted Solution

by:
91mustang earned 20 total points
ID: 10989523
Yes, that means program was crashing,and you were not printing stacktrace. that is why second insertQuery() was not going. The crash accurs after first insert. That is same as when i ran, but i added printStackTrace()

good luck with the reason next
0
 
LVL 4

Expert Comment

by:91mustang
ID: 11008384
thanks :-)
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
The viewer will learn how to implement Singleton Design Pattern in Java.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now