Results 1 to 7 of 7
  1. #1
    mathidioticz is offline Member
    Join Date
    Jan 2012
    Posts
    48
    Rep Power
    0

    Default What happen to the code?

    Here is the code.
    When i run it, the console would show that it is having a general error.

    Java Code:
     
    package cancer.entity;
    
    import OOPJ.database.DBController; 
    import Signup.entity.SignUp;
    
    import java.sql.ResultSet; 
    import java.util.ArrayList; 
    
    public class CancerDetails {
    
    	private String c_articleTitle;
    	private String c_articleDetails;
    	private String c_image1;
    
    
    	public CancerDetails(String cArticleTitle, String cArticleDetails,
    			String cImage1) {
    		super();
    		c_articleTitle = cArticleTitle;
    		c_articleDetails = cArticleDetails;
    		c_image1 = cImage1;
    	}
    
    
    
    	public CancerDetails() {
    	
    	}
    	
    	public static void main (String[] args) {
    		CancerDetails f1 = new CancerDetails();
    		f1.setC_articleTitle("heyhey");
    		f1.setC_articleDetails("meow");
    		f1.setC_image1("johnson");
    		
    		System.out.println(f1.createCancer());
    		System.out.println(f1.getC_articleTitle());
    		//To test update friend
    		f1.setC_articleTitle("Retest");
    		System.out.println(f1.updateCancer());
    
    		//To test retrieve friend
    	    CancerDetails f2 = new CancerDetails();
    		f2.retrieveCancer();
    		System.out.println(f2.getC_articleDetails());
    		
    	}
    
    	public String getC_articleTitle() {
    		return c_articleTitle;
    	}
    
    	public void setC_articleTitle(String cArticleTitle) {
    		c_articleTitle = cArticleTitle;
    	}
    
    	public String getC_articleDetails() {
    		return c_articleDetails;
    	}
    
    	public void setC_articleDetails(String cArticleDetails) {
    		c_articleDetails = cArticleDetails;
    	}
    
    	public String getC_image1() {
    		return c_image1;
    	}
    
    	public void setC_image1(String cImage1) {
    		c_image1 = cImage1;
    	}
    
    	public boolean retrieveCancer() { 
    		//declare local variables
    		boolean success = false; 
    		ResultSet rs = null; 
    		DBController db =  new DBController();
    		
    		db.setUp("CFDatabase");
    		
    		String dbQuery = "SELECT * FROM CANCER WHERE C_ARTICLETITLE ='" + c_articleTitle + "' and C_ARTICLEDETAILS = '" + c_articleDetails + "' and C_IMAGE1= '"+ c_image1+ "'";
    		
    		rs = db.readRequest(dbQuery); 
    		
    		try { 
    			if(rs.next()) { 
    				c_articleTitle = rs.getString("c_articleTitle");
    				c_articleDetails = rs.getString("c_articleDetails"); 
    				c_image1 = rs.getString("c_image1");
    				success = true; 
    				
    			}
    		 
    	}
    		catch(Exception e) { 
    			e.printStackTrace();
    		}
    		db.terminate(); 
    		return success;
    	}
    	
    	public boolean createCancer() { 
    		boolean success = false; 
    		ResultSet rs = null; 
    		DBController db = new DBController(); 
    		String dbQuery; 
    		db.setUp("CFDatabase"); 
    
    		dbQuery = "INSERT INTO CANCER(C_articleTitle, C_articleDetails,";
    		dbQuery = dbQuery +	"C_image1) VALUES (\'" + c_articleTitle + "', '";
    		dbQuery = dbQuery + c_articleDetails + "', '" + c_image1 + "')";
    
    		rs = db.updateRequestKey(dbQuery);
    		try{
    		if(rs.next()){
    			success = true;
    		}
    		}
    		
    		catch (Exception e){
    		e.printStackTrace();
    		}
    		db.terminate();
    		return success;
    		}
    	
    	public boolean updateCancer() { 
    		
    		boolean success = false; 
    		DBController db = new DBController(); 
    		
    		db.setUp("CFDatabase"); 
    		
    		String dbQuery = "UPDATE CANCER SET C_articleTitle = '" + c_articleTitle;
    		dbQuery = dbQuery + "', C_articleDetails= '" + c_articleDetails + "', C_image1 = '" + c_image1 + "' ";
    		
    		//step 2 of using DBController, use updateRequest method
    		if ( db.updateRequest(dbQuery) == 1){
    		success = true;
    		}
    		//step 3 of using DBController
    		db.terminate();
    		return success;
    		}
    	
    	}

    Here is the error :

    connection is jdbc:odbc:CFDatabase
    DB Query: INSERT INTO CANCER(C_articleTitle, C_articleDetails,C_image1) VALUES ('heyhey', 'meow', 'johnson')
    Connection is closed
    true
    heyhey
    connection is jdbc:odbc:CFDatabase
    DB Query: UPDATE CANCER SET C_articleTitle = 'Retest', C_articleDetails= 'meow', C_image1 = 'johnson'
    java.sql.SQLException: General error
    at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
    at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
    at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(Unknown Source)
    at sun.jdbc.odbc.JdbcOdbcStatement.execute(Unknown Source)
    at sun.jdbc.odbc.JdbcOdbcStatement.executeUpdate(Unkn own Source)
    at OOPJ.database.DBController.updateRequest(DBControl ler.java:64)
    at cancer.entity.CancerDetails.updateCancer(CancerDet ails.java:138)
    at cancer.entity.CancerDetails.main(CancerDetails.jav a:40)
    Connection is closed
    false
    connection is jdbc:odbc:CFDatabase
    DB Query: SELECT * FROM CANCER WHERE C_ARTICLETITLE ='null' and C_ARTICLEDETAILS = 'null' and C_IMAGE1= 'null'
    Connection is closed
    null


    Please help me, where did it got wrong?
    Last edited by mathidioticz; 01-21-2012 at 03:58 PM.

  2. #2
    Join Date
    Jan 2010
    Posts
    19
    Rep Power
    0

    Default Re: What happen to the code?

    Which database system are you using?

    If you put this statement in the console (some tool from the database system where you can execute sql statements) of the database, it executes fine?

    Java Code:
    INSERT INTO CANCER(C_articleTitle, C_articleDetails,C_image1) VALUES ('junetan1994', '91288888', 'junetan')

  3. #3
    mathidioticz is offline Member
    Join Date
    Jan 2012
    Posts
    48
    Rep Power
    0

    Default Re: What happen to the code?

    i am using microsoft access.

    it come out this general error when i run it. But when i check the access database, the data is store inside despite the fact that error occurs when i run it.

  4. #4
    mathidioticz is offline Member
    Join Date
    Jan 2012
    Posts
    48
    Rep Power
    0

    Default Re: What happen to the code?

    Please help me, i really need help for this java project.

  5. #5
    Join Date
    Jan 2010
    Posts
    19
    Rep Power
    0

    Default Re: What happen to the code?

    Quote Originally Posted by mathidioticz View Post
    i am using microsoft access.

    it come out this general error when i run it. But when i check the access database, the data is store inside despite the fact that error occurs when i run it.
    The update statement seems to be ok.
    When you say "data is stored inside" the database, it is the record with the field C_articleTitle equal to heyhey, right?

  6. #6
    mathidioticz is offline Member
    Join Date
    Jan 2012
    Posts
    48
    Rep Power
    0

    Default Re: What happen to the code?

    ya, it is stored under title. What happen to the code?-cancer.png

    but the update query is still having error ):

  7. #7
    Join Date
    Jan 2010
    Posts
    19
    Rep Power
    0

    Default Re: What happen to the code?

    The table Cancel has a primary key? It is the field c_articleTitle? If it this field, then you cannot have two records with the same primary key.

    The error occurs when you does a update to change the c_articleTitle to "Retest". Then maybe this is the problem.

Similar Threads

  1. Replies: 0
    Last Post: 08-07-2011, 08:32 PM
  2. Replies: 5
    Last Post: 07-14-2011, 07:45 AM
  3. what happen whene jar file (j2me) install on mobile device ???
    By mahdi-farzami in forum CLDC and MIDP
    Replies: 2
    Last Post: 06-18-2010, 01:15 PM
  4. what happen if an object set to null
    By SaYuNaRa in forum New To Java
    Replies: 5
    Last Post: 04-17-2008, 04:15 AM
  5. To happen of ActionErrors to ActionMessage
    By Eric in forum New To Java
    Replies: 1
    Last Post: 07-05-2007, 07:09 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •