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

    Default Error: Too few parameters. Expected 1.

    Java Code:
    package HealthOK.entity;
    
    import OOPJ.database.DBController;
    import java.sql.ResultSet;
    import java.util.ArrayList;
    
    public class Forum {
    	public static void main (String[] args) {
    		// To test create friend
    
    		Forum f1 = new Forum();
    		f1.setF_topic("fujhdirnf");
    		f1.setUsername("dsfdf");
    		f1.setF_message("sdgfdgv");
    		System.out.println(f1.createForumQuestion());
    
    		// To test update friend
    		System.out.println(f1.updateForumQuestion());
    
    		// To test delete friend
    		System.out.println(f1.deleteForumQuestion());
    
    		// To test retrieve friend
    		Forum f2 = new Forum();
    		f2.retrieveForumQuestion();
    		System.out.println(f2.getF_topic());		
    	}
    
    	
    	private String f_topic;
    	private String username;
    	private String f_message;
    	
    	public Forum() {
    		
    	}
    
    	public Forum(String fTopic) {
    		super();
    		f_topic = fTopic;
    	}
    
    	public Forum(String fTopic, String username, String fMessage) {
    		super();
    		f_topic = fTopic;
    		this.username = username;
    		f_message = fMessage;
    	}
    
    	public String getF_topic() {
    		return f_topic;
    	}
    
    	public void setF_topic(String fTopic) {
    		f_topic = fTopic;
    	}
    
    	public String getUsername() {
    		return username;
    	}
    
    	public void setUsername(String username) {
    		this.username = username;
    	}
    
    	public String getF_message() {
    		return f_message;
    	}
    
    	public void setF_message(String fMessage) {
    		f_message = fMessage;
    	}
    
    	public Forum(String username, String fMessage) {
    		super();
    		this.username = username;
    		f_message = fMessage;
    	}
    	
    	public boolean retrieveForumQuestion() {
    		boolean success = false;
    		ResultSet rs = null;
    		DBController db = new DBController();
    		
    		db.setUp("CFDatabase");
    		
    		String dbQuery = "SELECT * FROM FORUMQUESTION WHERE ID =" + f_topic;
    		rs = db.readRequest(dbQuery);
    		try {
    			if(rs.next()){
    				f_topic = rs.getString("f_topic");
    				username = rs.getString("username");
    				f_message = rs.getString("f_message");
    				success = true;
    				
    			}
    		}
    		catch (Exception e) {
    			e.printStackTrace();
    		}
    		db.terminate();
    		return success;
    	}
    
    	public boolean createForumQuestion() {
    		 boolean success = false;
    		 ResultSet rs = null;
    		 DBController db = new DBController();
    		 String dbQuery;
    		 db.setUp("CFDatabase");
    		 
    		 if ( f_topic == " ") {
    			 dbQuery = "INSERT INTO FORUMQUESTION (username,";
    			 dbQuery = dbQuery + " f_message) VALUES (\'" + f_topic + "', '";
    			 dbQuery = dbQuery + username + "', '" + f_message + "')";
    		 }
    		 else {
    			 dbQuery = "INSERT INTO FORUMQUESTION (f_topic, username,";
    			 dbQuery = dbQuery + " f_message) VALUES (" + f_topic + ",'" + username + "', '";
    			 dbQuery = dbQuery + f_message + "')";
    			 
    		 }
    		 rs = db.updateRequestKey(dbQuery);
    		 try{
    			    if (rs.next()){
    			        // this will return the ID which is a auto number primary key 
    			        f_topic = rs.getString(1);
    			        success = true;     
    			    }
    			}
    			catch (Exception e) {
    			   e.printStackTrace();
    			}
    			db.terminate();
    			return success;
    		}
    	 public boolean updateForumQuestion() {
    			
    			// declare local variables
    			boolean success = false;
    			DBController db = new DBController();
    			db.setUp("CFDatabase");
    			
    			String dbQuery = "UPDATE FORUMQUESTION SET f_topic = '" + f_topic; 
    			dbQuery = dbQuery + "', username = '" + username;
    			dbQuery = dbQuery + "', f_message ='" + f_message + "' WHERE ID = " + f_topic; 
    			
    			// step 2 of using DBController, use updateRequest method 
    			if (db.updateRequest(dbQuery) == 2){
    			        success = true;
    			}
    			// step 3 of using DBController 
    			db.terminate();
    			return success;
    		}
    	 public boolean deleteForumQuestion(){
    			// declare local variables
    			boolean success = false;
    			DBController db = new DBController();
    
    			// step 1 of using DBcontroller, passing data source name
    			db.setUp("CFDatabase");
    			String dbQuery = "DELETE FROM FORUMQUESTION WHERE ID = " + f_topic; 
    
    			// step 2 of using DBcontroller, use updateRequest method 
    			if (db.updateRequest(dbQuery) == 1){
    				success = true;
    			}
    			// step 3 of using DBController 
    			db.terminate();
    			return success;
    	 }
    	 
    }

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,519
    Blog Entries
    7
    Rep Power
    20

    Default Re: Error: Too few parameters. Expected 1.

    And now what? Do you want us to guess where the error might be?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

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

    Default Re: Error: Too few parameters. Expected 1.

    When i run this application, it often shows "Too few parameters. Expected 1." error. So i do not know where does the error come from and how to solve it.
    Thankyou very much for the help.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,397
    Rep Power
    25

    Default Re: Error: Too few parameters. Expected 1.

    Can you copy and paste here the full text of the error messages?

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

    Default Re: Error: Too few parameters. Expected 1.

    connection is jdbc:odbc:CFDatabase
    DB Query: INSERT INTO FORUMQUESTION (f_topic, username, f_message) VALUES (fujhdirnf,'dsfdf', 'sdgfdgv')
    java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.
    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.updateRequestKey(DBCont roller.java:84)
    at HealthOK.entity.Forum.createForumQuestion(Forum.ja va:123)
    at HealthOK.entity.Forum.main(Forum.java:15)
    java.lang.NullPointerException
    at HealthOK.entity.Forum.createForumQuestion(Forum.ja va:125)
    at HealthOK.entity.Forum.main(Forum.java:15)
    Connection is closed
    false
    connection is jdbc:odbc:CFDatabase
    DB Query: UPDATE FORUMQUESTION SET f_topic = 'fujhdirnf', username = 'dsfdf',f_message ='sdgfdgv' WHERE ID = fujhdirnf
    java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 2.
    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 HealthOK.entity.Forum.updateForumQuestion(Forum.ja va:149)
    at HealthOK.entity.Forum.main(Forum.java:18)
    Connection is closed
    false
    java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 2.
    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 HealthOK.entity.Forum.deleteForumQuestion(Forum.ja va:166)
    at HealthOK.entity.Forum.main(Forum.java:21)
    connection is jdbc:odbc:CFDatabase
    DB Query: DELETE FROM FORUMQUESTION WHERE ID = fujhdirnf
    Connection is closed
    false
    java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.
    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.executeQuery(Unkno wn Source)
    at OOPJ.database.DBController.readRequest(DBControlle r.java:47)
    at HealthOK.entity.Forum.retrieveForumQuestion(Forum. java:88)
    at HealthOK.entity.Forum.main(Forum.java:25)
    java.lang.NullPointerException
    at HealthOK.entity.Forum.retrieveForumQuestion(Forum. java:90)
    at HealthOK.entity.Forum.main(Forum.java:25)
    connection is jdbc:odbc:CFDatabase
    DB Query: SELECT * FROM FORUMQUESTION WHERE ID =null
    Connection is closed
    null

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,397
    Rep Power
    25

    Default Re: Error: Too few parameters. Expected 1.

    java.lang.NullPointerException
    at HealthOK.entity.Forum.createForumQuestion(Forum.ja va:125)
    This part of the error message says that there is a variable with a null value on line 125

Similar Threads

  1. ';' expected error
    By name in forum New To Java
    Replies: 19
    Last Post: 12-23-2011, 08:09 AM
  2. Replies: 3
    Last Post: 08-15-2011, 10:16 AM
  3. Error: '{' expected
    By romina in forum New To Java
    Replies: 1
    Last Post: 07-26-2007, 09:34 AM
  4. My error is: ')' expected
    By silvia in forum New To Java
    Replies: 1
    Last Post: 07-18-2007, 04:49 PM
  5. MSG ERROR: : expected
    By Marty in forum New To Java
    Replies: 1
    Last Post: 05-31-2007, 02:21 AM

Posting Permissions

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