What is wrong with my simple program!

Hello everybody,
I have a very simple Java program, but it could not run as i expect.
Could anybody help me firgure it out ?
Thank you very much in advance
still_learn
Here is my program:
import java.io.*;
public class Practice
static InputStreamReader reader = new
InputStreamReader(System.in);
static BufferedReader keyboard = new BufferedReader
(reader);
public static void main(String[] args) throws
IOException
String response;
do{
     System.out.println("");
     for(int i=0; i<20; i++)
     System.out.println("George Michael");
     do{
     System.out.print("Do you want to continue?
(y/n) ");
     response = keyboard.readLine();
     }while((response != "y")&&(response != "n"));
          }while(response == "y");
}// end of main
}// end of class

You didn't say what you expected, so debugging becomes very difficult. However I do notice at the end of the code that you compare two strings using == and !=. This does not work. If you want to see if two strings have the same content, use the equals() method of the String class. In your case:}while((!response.equals("y"))&&(!response.equals("n")));
}while(response.equals("y");

Similar Messages

  • What's wrong with this simple code?

    What's wrong with this simple code? Complier points out that
    1. a '{' is expected at line6;
    2. Statement expected at the line which PI is declared;
    3. Type expected at "System.out.println("Demostrating PI");"
    However, I can't figure out them. Please help. Thanks.
    Here is the code:
    import java.util.*;
    public class DebugTwo3
    // This class demonstrates some math methods
    public static void main(String args[])
              public static final double PI = 3.14159;
              double radius = 2.00;
              double area;
              double roundArea;
              System.out.println("Demonstrating PI");
              area = PI * radius * radius;
              System.out.println("area is " + area);
              roundArea = Math.round(area);
              System.out.println("Rounded area is " + roundArea);

    Change your code to this:
    import java.util.*;
    public class DebugTwo3
         public static final double PI = 3.14159;
         public static void main(String args[])
              double radius = 2.00;
              double area;
              double roundArea;
              System.out.println("Demonstrating PI");
              area = PI * radius * radius;
              System.out.println("area is " + area);
              roundArea = Math.round(area);
              System.out.println("Rounded area is " + roundArea);
    Klint

  • HELP!What's wrong with my GZIP program?

    Here's part of the source code:
    static void Compress(String strfilename)     
         int iTemp;
         try
              BufferedReader brIn=new BufferedReader(new FileReader(strfilename));
              BufferedOutputStream bosOut=new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(strfilename+".gz")));
              while(true)
                   iTemp=brIn.read();
                   if(iTemp==-1) break;
                   bosOut.write(iTemp);                         }
              brIn.close();
              bosOut.close();
         catch(Exception e)
              System.out.println("Error: "+e);
    If I use it to compress a small file(20k),the compression is successful,and I can also see it using WINRAR;but once I decompress
    this GZIP file,all the English words are correct,while other unicodes
    such as Chinese become unrecognizable;
    If I use it to compress a "large" file(3M) such as abc.chm,the size of the compressed file is about 2M(INCREDIBLE! WINRAR can only decrease
    the size of this file by 30k);But..the size of decompressed file is
    still about 2M,and windows cannot read it (Invalid page error).
    I wonder what's wrong with my program? Even if I use "javac -encoding
    gb2312 ..." to compile my program,the result is also the same.
    HOW SHOULD I DO??

    Hi, jchc,
    Let me help you a little bit, here. hwalkup is correct that for data compression you should use input and output stream instead of readers and writers. I don't think that mixing a reader with an output stream would work anyway as streams read and write bytes (8-bit data), while readers and writers read and write characters (16-bit data). hwalkup is also correct to suggest that you should use a buffer (a byte[]) to improve the performance of your streaming processes.
    Here is code for methods to compress and decompress one file into another. Note: the decompress() method will throw an IOException if the file to decompress (inFile) is not actually compressed in the first place.
        public static void compress(File inFile, File outFile)
                throws FileNotFoundException, IOException {
            InputStream in = null;
            OutputStream out = null;
            try {
                in = new BufferedInputStream(new FileInputStream(inFile));
                GZIPOutputStream gzipOut = new GZIPOutputStream(
                                           new FileOutputStream(outFile));
                out = new BufferedOutputStream(gzipOut);
                byte[] buffer = new byte[512];
                for (int i = 0; (i = in.read(buffer)) > -1; ) {
                    out.write(buffer, 0, i);
                out.flush();
                gzipOut.finish(); // absolutely necessary
            } finally {
                // always close your output streams before your input streams
                if (out != null) {
                    try {
                        out.close();
                    } catch (IOException e) {
                if (in != null) {
                    try {
                        in.close();
                    } catch (IOException e) {
        public static void decompress(File inFile, File outFile)
                throws FileNotFoundException, IOException {
            InputStream in = null;
            OutputStream out = null;
            try {
                GZIPInputStream gzipIn = new GZIPInputStream(
                                         new FileInputStream(inFile));
                in = new BufferedInputStream(gzipIn);
                out = new BufferedOutputStream(new FileOutputStream(outFile));
                byte[] buffer = new byte[512];
                for (int i = 0; (i = in.read(buffer)) > -1; ) {
                    out.write(buffer, 0, i);
                out.flush();
            } finally {
                // always close your output streams before your input streams
                if (out != null) {
                    try {
                        out.close();
                    } catch (IOException e) {
                if (in != null) {
                    try {
                        in.close();
                    } catch (IOException e) {
        }Shaun

  • What's wrong with a simple login.jspx?

    Hello,
    I wrote a simple login.jspx page by following the indications at http://download.oracle.com/docs/cd/E15523_01/web.1111/b31974/adding_security.htm#BABDEICH
    Now, the page works with Firefox 5, but does not with IE 7. When under IE 7, the page keeps reloading giving errors about *"AdfBootStrap undefined*" or *"AdfLogger undefined".*
    What is wrong? Please note that I have already read all the threads on the forum about this issue, without actually solving my problem (I have not really seen any useful solutions there to be honest).
    Jdeveloper is 11.1.1.5.0, only adf authentication is enabled.
    The error messages are like the following ones:
    http://forums.oracle.com/forums/thread.jspa?threadID=952977&tstart=29
    thanks.
    Edited by: user10047839 on 27-giu-2011 8.07
    Changing from jspx to jsp does not solve the problem.

    Hello codeplay,
    in the source code of the page I have the following similar to your line:
    <script type="text/javascript" src="/Myapp/afr/partition/ie/default/opt/boot-11.1.1.5.0-1095.js"></script>
    No lines with SHERMAN inside.
    I could not open "/Myapp/afr/partition/ie/default/opt/boot-11.1.1.5.0-1095.js" or
    "afr/partition/ie/default/opt/boot-11.1.1.5.0-1095.js". Page not found
    Why does it happen with login page only?
    In firefox, as opposite to ie, where the page is rendered a little better (not as good as it should be though, due to these problems), I can login and be redirected to the secured main page, which is another .jsp, more complex than the simple login page, and there I have no problems at all.
    I noticed that the badly rendered page has a link pointing to the generated html below. NOTE that JavaScript IS ENABLED in my IE despite what this html says at the end. I checked this twice:
    WHAT IS WRONG??????????
    <html lang="en-EN"><head><script>
    ** Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
    * This is the loopback script to process the url before the real page loads. It introduces
    * a separate round trip. During this first roundtrip, we currently do two things:
    * - check the url hash portion, this is for the PPR Navigation.
    * - do the new window detection
    * the above two are both controled by parameters in web.xml
    * Since it's very lightweight, so the network latency is the only impact.
    * here are the list of will-pass-in parameters (these will replace the param in this whole
    * pattern:
    * viewIdLength view Id length (characters),
    * loopbackIdParam loopback Id param name,
    * loopbackId loopback Id,
    * loopbackIdParamMatchExpr loopback Id match expression,
    * windowModeIdParam window mode param name,
    * windowModeParamMatchExpr window mode match expression,
    * clientWindowIdParam client window Id param name,
    * clientWindowIdParamMatchExpr client window Id match expression,
    * windowId window Id,
    * initPageLaunch initPageLaunch,
    * enableNewWindowDetect whether we want to enable new window detection
    * jsessionId session Id that needs to be appended to the redirect URL
    * enablePPRNav whether we want to enable PPR Navigation
    var id = null;
    var query = null;
    var href = document.location.href;
    var hashIndex = href.indexOf("#");
    var hash = null;
    /* process the hash part of the url, split the url */
    if (hashIndex > 0)
    hash = href.substring(hashIndex + 1);
    /* only analyze hash when pprNav is on (bug 8832771) */
    if (false && hash && hash.length > 0)
    hash = decodeURIComponent(hash);
    if (hash.charAt(0) == "@")
    query = hash.substring(1);
    else
    var state = hash.split("@");
    id = state[0];
    query = state[1];
    href = href.substring(0, hashIndex);
    /* process the query part */
    var queryIndex = href.indexOf("?");
    if (queryIndex > 0)
    /* only when pprNav is on, we take in the query from the hash portion */
    query = (query || (id && id.length>0))? query: href.substring(queryIndex);
    href = href.substring(0, queryIndex);
    var jsessionIndex = href.indexOf(';');
    if (jsessionIndex > 0)
    href = href.substring(0, jsessionIndex);
    /* we will replace the viewId only when pprNav is turned on (bug 8832771) */
    if (false)
    if (id != null && id.length > 0)
    href = href.substring(0, href.length - 10) + id;
    var isSet = false;
    if (query == null || query.length == 0)
    query = "?";
    else if (query.indexOf("_afrLoop=") >= 0)
    isSet = true;
    query = query.replace(/_afrLoop=[^&]*/, "_afrLoop=12570889997779");
    else
    query += "&";
    if (!isSet)
    query = query += "_afrLoop=12570889997779";
    /* below is the new window detection logic */
    var initWindowName = "_afr_init_"; // temporary window name set to a new window
    var windowName = window.name;
    // if the window name is "_afr_init_", treat it as redirect case of a new window
    if ((true) && (!windowName || windowName==initWindowName ||
    windowName!="1bvr27bkx4_1"))
    /* append the _afrWindowMode param */
    var windowMode;
    if (false)
    /* this is the initial page launch case,
    also this could be that we couldn't detect the real windowId from the server side */
    windowMode=0;
    else if ((href.indexOf("/__ADFvDlg__") > 0) || (query.indexOf("__ADFvDlg__") >= 0))
    /* this is the dialog case */
    windowMode=1;
    else
    /* this is the ctrl-N case */
    windowMode=2;
    if (query.indexOf("_afrWindowMode=") >= 0)
    query = query.replace(/_afrWindowMode=[^&]*/, "_afrWindowMode="+windowMode);
    else
    query = query += "&_afrWindowMode="+windowMode;
    /* append the _afrWindowId param */
    var clientWindowId;
    /* in case we couldn't detect the windowId from the server side */
    if (!windowName || windowName == initWindowName)
    clientWindowId = "null";
    // set window name to an initial name so we can figure out whether a page is loaded from
    // cache when doing Ctrl+N with IE
    window.name = initWindowName;
    else
    clientWindowId = windowName;
    if (query.indexOf("_afrWindowId=") >= 0)
    query = query.replace(/_afrWindowId=\w*/, "_afrWindowId="+clientWindowId);
    else
    query = query += "&_afrWindowId="+clientWindowId;
    var sess = "";
    if (sess.length > 0)
    href += sess;
    /* if pprNav is on, then the hash portion should have already been processed */
    if ((false) || (hash == null))
    document.location.replace(href + query);
    else
    document.location.replace(href + query + "#" + hash);
    </script><noscript>JavaScript is not enabled in your browser.</noscript></head></html>

  • What's wrong with my simple syntax?

    Hi, Im trying to create a var and then check it with an if
    statment but its not working, whats going wrong?
    var loggedin:String = new String();
    loggedin = ("yes");
    if (loggedin == "yes")
    searchbox1.text = ("user logged in");

    Your code worked for me:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="
    http://www.adobe.com/2006/mxml"
    creationComplete="init()">
    <mx:Script>
    <![CDATA[
    import mx.collections.ArrayCollection;
    private var ac:ArrayCollection = new ArrayCollection();
    public function init():void
    var loggedin:String = new String();
    loggedin = ("yes");
    if (loggedin == "yes")
    searchbox1.text = ("user logged in");
    ]]>
    </mx:Script>
    <mx:TextArea id="searchbox1"/>
    </mx:Application>

  • What is wrong with this simple PL/SQL..

    Hello,
    I made a PL/SQL to recreate user (if user exits already, then drop/recreate)
    I run this script and it won't drop the existed user as expected, what is wrong..?
    run like:
    $ sqlplus system/password@dbname @create_user.sql 'A1' --A1 is a user who already existed.
    conn /as sysdba
    SET FEEDBACK OFF SERVEROUTPUT ON VERIFY OFF TERMOUT OFF
    DECLARE
    v_count INTEGER := 0;
    v_statement VARCHAR2 (200);
    BEGIN
    SELECT COUNT (1)
    INTO v_count
    FROM dba_users
    WHERE username = UPPER ('&1');
    IF v_count != 0
    THEN
    EXECUTE IMMEDIATE ('DROP USER &1 CASCADE');
    END IF;
    v_statement :=
    'CREATE USER &1 IDENTIFIED BY &1'
    || ' DEFAULT TABLESPACE USER_DATA'
    || ' TEMPORARY TABLESPACE TEMPORARY_DATA'
    || ' PROFILE DEFAULT ACCOUNT UNLOCK';
    EXECUTE IMMEDIATE (v_statement);
    -- Grant permissions
    EXECUTE IMMEDIATE ('GRANT READ_USER TO &1 WITH ADMIN OPTION');
    EXECUTE IMMEDIATE ('ALTER USER &1 DEFAULT ROLE ALL');
    EXECUTE IMMEDIATE ('GRANT CREATE PUBLIC SYNONYM TO &1');
    EXECUTE IMMEDIATE ('GRANT CREATE DATABASE LINK TO &1');
    EXECUTE IMMEDIATE ('GRANT CREATE SNAPSHOT TO &1');
    EXECUTE IMMEDIATE ('GRANT CREATE TABLE TO &1');
    EXECUTE IMMEDIATE ('GRANT DROP PUBLIC SYNONYM TO &1');
    EXECUTE IMMEDIATE ('GRANT QUERY REWRITE TO &1');
    EXECUTE IMMEDIATE ('GRANT RESTRICTED SESSION TO &1');
    EXECUTE IMMEDIATE ('GRANT SELECT ANY DICTIONARY TO &1');
    EXECUTE IMMEDIATE ('GRANT SELECT ANY TABLE TO &1');
    EXECUTE IMMEDIATE ('GRANT UNLIMITED TABLESPACE TO &1');
    EXECUTE IMMEDIATE ('GRANT SELECT ON SYS.CHANGE_TABLES TO &1');
    EXECUTE IMMEDIATE ('GRANT SELECT ON SYS.DBA_SUBSCRIBED_TABLES TO &1');
    EXECUTE IMMEDIATE ('GRANT SELECT ON SYS.DBA_SUBSCRIPTIONS TO &1');
    EXECUTE IMMEDIATE ('GRANT EXECUTE ON SYS.DBMS_CDC_PUBLISH TO &1');
    EXECUTE IMMEDIATE ('GRANT EXECUTE ON SYS.DBMS_CDC_SUBSCRIBE TO &1');
    EXECUTE IMMEDIATE ('GRANT EXECUTE ON SYS.DBMS_CDC_UTILITY TO &1');
    EXECUTE IMMEDIATE ('GRANT EXECUTE ON SYS.DBMS_LOCK TO &1');
    EXECUTE IMMEDIATE ('GRANT EXECUTE ON SYS.DBMS_SYSTEM TO &1');
    EXECUTE IMMEDIATE ('GRANT EXECUTE ON SYS.DBMS_UTILITY TO &1');
    EXECUTE IMMEDIATE ('GRANT READ, WRITE ON DIRECTORY SYS.PUBLIC_ACCESS TO &1 WITH GRANT OPTION');
    DBMS_OUTPUT.put_line (' ');
    DBMS_OUTPUT.put_line ('User &1 created successfully');
    DBMS_OUTPUT.put_line (' ');
    EXCEPTION
    WHEN OTHERS
    THEN
    DBMS_OUTPUT.put_line (SQLERRM);
    DBMS_OUTPUT.put_line (' ');
    END;
    Exit;
    EOF
    Thank you
    Jerry

    Hi,
    I try to run this command in a shel scriptl, following this pl/sql excuting is a exp core shcema/imp to this user by using pipe.
    (--this part is working well)
    so I try to debug the pl/sql part first that is why I didn't use & or &&, which need to interactive with computer on scene, but this shell script will run automatically by scheduler.
    this is the whole shell,
    #!/bin/ksh
    INPUT_DATABASE_SCHEMA=$1
    OUTPUT_DATABASE_SCHEMA=$2
    TARGET_DATABASE=$3
    #drop/recreate user $2
    sqlplus system/$3@$3 @create_user.sql '$2' ---this is also the question? how make it as real variable $2, not literal
    #exp
    mknod ./$1_exp p
    gzip < $1_exp > ./$1_exp.dmp.gz &
    exp \
    rows=y \
    userid=system/$3@$3 \
    owner=$1 \
    log=$1_exp.log \
    file=$1_exp \
    direct=y \
    recordlength=65535 \
    statistics=none \
    consistent=y \
    compress=n \
    grep 'ORA-' $1_exp.log
    if [ $? = 0 ]
    then
    mail -s "Problem in regression snapshort export" email < $1_exp.log
    fi
    #imp
    mknod ./$1_exp p
    gunzip < $1_exp.dmp.gz > $1_exp &
    imp \
    userid=system/$3@$3 \
    file=$1_exp \
    log=$2_IMP.log \
    buffer=500000000 \
    ignore=y \
    commit=y \
    fromuser=$1 \
    touser=$2 \
    feedback=100000 \
    GRANTS=n \
    grep 'ORA-' $2_IMP.log
    if [ $? = 0 ]
    then
    mail -s "Erros found in regression snapshort import" email < $2_IMP.log
    else
    mail -s "regression snapshort is done sucessfully" email < $2_IMP.log
    fi
    #recompile invalid
    sqlplus system/$3@$3 << EOF
    conn /as sysdba
    @?/rdbms/admin/utlrp.sql
    Exit;
    EOF
    thank you in advance

  • What's wrong with this simple method

    i'm having compile troubles with this simple method, and i think it's got to be something in my syntax.
    public String setTime()
    String timeString = new String("The time is " + getHours() + ":" + getMinutes() + ":" + getSeconds() + " " + getIsAM());
    return timeString;
    this simple method calls the get methods for hours, minutes, seconds, and isAM. the compiler tells me i need another ) right before getSeconds(), but i don't believe it. i know this is a simple one, but i could use the advice.
    thanks.

    Hi,
    I was able to compile this method , it gave no error

  • What is wrong with my simple class program?

    Ok, I'm writing a simple class called 'Frog', which will keep track of the position enter by a user. The program will ask for the initial position for the frog. It will then ask for how many steps it want the frog to jump. Then it will output the new position of it. But for some reason, it doesn't work. It always output 0 for some reason.
    import java.io.*;
    import java.util.*;
    - frog program class.
    frog will start on a position.
    user will be prompt to ask how many jump to forward.
    public class beta
         public static void main(String args[]) throws IOException
              class Frog
              int newPos;
                   int Position () //return postion of the frog
                   return newPos;
                   void PositionStart (int newPos) //initial postion of the frog
                   newPos = newPos;
                   int Jump(int stepsForward, int newPos)
                        newPos+=stepsForward;
                        return newPos;
                   int PrevPos(int newPos)
                   return newPos-1;
                   int NextPos(int newPos)
                   return newPos+1;
                   boolean isMagicSquare(int newPos)
                        if(newPos == 5) return true;
                        else return false;
         BufferedReader key = new BufferedReader(new InputStreamReader(System.in));
         Frog joe = new Frog();
         int pos = 0, stepsFoward = 0;
                   //input 1-9
                   do
                        System.out.println("Enter a position for the frog: ");
                        pos = Integer.parseInt(key.readLine()); //reads in an integer
                   }while(pos < 1 || pos > 9);
                   joe.PositionStart(pos); //initialize the position for the frog
                   System.out.println("Pos: " + joe.Position()); //position
                   System.out.println("How many steps to jump: ");
                   stepsFoward = Integer.parseInt(key.readLine());
                   joe.Jump(stepsFoward,joe.Position());
                   System.out.println("New Position: " + joe.Position());               
    }

    You have method argument parameters with the same name as a member variable; as in:
    void PositionStart (int newPos) {
            newPos = newPos;
    }You need to identify to the compiler which variable is which, class member variables in cases like this should be qualified with the this keyword; as in:
    void PositionStart (int newPos) {
            this.newPos = newPos;
    }Dave

  • Can anyone tell me what is wrong with the simple sql?

    Hi,
    I have a simple SQL (see attached). It returns records when it does not include the Order By sorting clause. However, if it includes the Order By clause, Oracle says no data found. Anyone can give me some ideas what could cause the problem?
    Thanks in advance.
    SELECT ih.item_key, e.episode_key, e.episode_date, wp.work_package_key, p.patient_name, c.codes_key
    FROM work_package wp, episodes e, item_header ih, patients p, codes c, station_element se, station_data sd
    WHERE wp.work_item_key = e.episode_key
    and e.episode_key = ih.item_key
    and ih.logical_parent_key = p.patient_key
    and e.episode_type = c.code_value
    and wp.asgn_station_key = se.item_key
    and se.station_name like 'DICT FIX%'
    and sd.station_key = wp.asgn_station_key
    and (sd.facility = '0' or sd.facility = 1)
    and wp.on_hold <> 'Y' and c.code_type = 'CEPT'
    and c.setup_group = 1
    ORDER BY e.episode_date, e.medrec_no;

    Hmmm...can you post a SQL Plus session that demonstrates this?

  • What is wrong with this Swing program?

    Hi all,
    I wrote program:
    1) which should display JTable as part of JTree node
    2)In the table it has to display one column with JComboBox in each cell.
    I can get the first one, but not getting the JComboBox in it.
    I am pasting the code below.
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.tree.*;
    import java.util.*;
    import javax.swing.table.*;
    public class TableInTree extends JFrame
    public TableInTree()
    super("TableInTree");
    JTree tree = new JTree(this.createTreeModel());
    tree.setCellRenderer(new ResultTreeCellRenderer());
    this.getContentPane().add(new JScrollPane(tree));
    public static void main(String[] args)
    TableInTree frame = new TableInTree();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(800, 600);
    frame.show();
    private JTable createTable()
    TableColumn column=new TableColumn();
    column.setHeaderValue(new String("Sport"));
    JComboBox comboBox = new JComboBox();
    comboBox.addItem("Snowboarding");
    comboBox.addItem("Rowing");
    comboBox.addItem("Knitting");
    comboBox.addItem("Speed reading");
    comboBox.addItem("Pool");
    comboBox.addItem("None of the above");
    column.setCellEditor(new DefaultCellEditor(comboBox));
    column.setCellRenderer(new DefaultTableCellRenderer());
    JTable table = new JTable();
    table.addColumn(column);
    //DefaultCellEditor tce=new DefaultCellEditor();
    //table.setCellEditor(tce);
    //table.setDefaultRenderer(Object.class,new DefaultTableCellRenderer());
    //TableRenderDemo table2=new TableRenderDemo();
    return table;
    // * Method createRootNodes.
    private TreeModel createTreeModel()
    DefaultMutableTreeNode root = new DefaultMutableTreeNode("root");
    DefaultMutableTreeNode node1 = new DefaultMutableTreeNode("test1");
    node1.add(new DefaultMutableTreeNode(this.createTable()));
    root.add(node1);
    root.add(new DefaultMutableTreeNode("test2"));
    return new DefaultTreeModel(root, true);
    public static class ResultTreeCellRenderer extends DefaultTreeCellRenderer
    public Component getTreeCellRendererComponent(JTree t, Object value,boolean s, boolean o,boolean l, int r, boolean h)
    if (value instanceof DefaultMutableTreeNode)
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
    if (node.getUserObject() instanceof JTable)
    return new JScrollPane((JTable) node.getUserObject());
    return super.getTreeCellRendererComponent(t, value, s, o, l, r, h);
    Can anyone pls provode solution for it.
    thanks in advance
    amar

    I think you should configure the TableColumn after setModel for the JTable.

  • What is wrong with this simple CFIF statement?

    Hi, I've included a simple cfif statment to check to see if a
    user is already in the database, for some reaons the <cfelse>
    part of the statement does not work. that is, if the user is there
    it returns the recordcount and ID etc. but if it is a new user (no
    records found) it is just blank (without the nothing doing !!!) any
    ideas?
    Thanks
    Yankee

    Based strictly on the code you have shown, you do not need
    the query="getuser" in your cfoutput tag.
    Also, I would check to see if the value is greater than zero
    rather than equal to one. What if the person has more than one
    record in the database?
    Try this...
    <CFIF getuser.recordcount GT 0>
    #GetUser.RecordCount# Records Found
    <CFELSE>
    Doing Nothing
    </CFIF>

  • What is wrong with this simple query

    Hi,
    I am writting a simple code just to get the maximum no values from a database table
    The query is
    ResultSet = stm.executeQuery("SELECT MAX(column_name) FROM Database_table ");
    it seems to be a simple one but i am getting the message
    column not found
    Please answer soon

    Well, it depends on how your resultset is retrieving the results. If you retrieve by column name, then that's your problem. You need to do something like this:
    ResultSet = stm.executeQuery("SELECT MAX(column_name) AS myColumnName FROM Database_table ");
    String myResult = ResultSet.getString(myColumnName);Using MAX, COUNT, etc, will return your result with a mangled or no actual column name to retrieve from. Optionally, you can solve your problem by:
    ResultSet.getString(1);Michael Bishop

  • What's wrong with this simple java file

    I am learning java input methods. When I tried to compile the below simple java file, there were two errors.
    import java.io.*;
    public class MainClass {
       public static void main(String[] args)  {
        Console console = System.console();
        String user = console.readLine("user: ");
        System.out.println(user);
    }The compiler errors:
    h:\java\MainClass.java:5: cannot resolve symbol
    symbol : class Console
    location: class MainClass
    Console console = System.console();
    ^
    h:\java\MainClass.java:5: cannot resolve symbol
    symbol : method console ()
    location: class java.lang.System
    Console console = System.console();
    ^
    2 errors
    Could anyone take a look and shed some lights on this?

    I have changed to "import java.io.Console;" but this below errors:
    h:\java\MainClass.java:1: cannot resolve symbol
    symbol : class Console
    location: package io
    import java.io.Console;
    ^
    h:\java\MainClass.java:5: cannot resolve symbol
    symbol : class Console
    location: class MainClass
    Console console = System.console();
    ^
    h:\java\MainClass.java:5: cannot resolve symbol
    symbol : method console ()
    location: class java.lang.System
    Console console = System.console();
    ^
    3 errors
    -----------

  • What is wrong with this simple JSP code?

    Whenever I run it on a browser it goes the SQL exception, but when I run it in a Java compiler it works fine.
    Any help very much appreciated
    <head>
    <%@ page
         import = "java.io.*"
         import = "java.lang.*"
         import = "java.sql.*"
    %>
    <title>
    JSP Example 2
    </title>
    </head>
    <body>
    <h1>JSP Example 2</h1>
    <%
    try
    // Load the driver class
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
         try
         // Define the data source for the driver
              String sourceURL = "jdbc:odbc:my_library";
         // Create a connection through the DriverManager
              Connection databaseConnection = DriverManager.getConnection(sourceURL,"","");
              out.println("Here");
         Statement statement = databaseConnection.createStatement();
         ResultSet authorNames = statement.executeQuery("Select * from tblAvailable_Items");
         catch (SQLException s)
              out.println("SQL Error<br>");
         catch (ClassNotFoundException err)
              out.println("Class loading error");
    %>
    </body>
    </html>

    Hi...
    I have made some modifications to your code.. Try this. I assume, you would configured the system dsn as my_library, a table name "Table1" with one of the fields name as "name"
    <head>
    <%@ page import = "java.io.*,java.lang.*,java.sql.*" %>
    <title>
    JSP Example 2
    </title>
    </head>
    <body>
    <h1>JSP Example 2</h1>
    <%
    try
    // Load the driver class
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    try
    // Define the data source for the driver
    String sourceURL = "jdbc:odbc:my_library";
    // Create a connection through the DriverManager
    Connection databaseConnection = DriverManager.getConnection(sourceURL,"","");
    out.println("Here");
    Statement statement = databaseConnection.createStatement();
    String sql = "select * from Table1";
    ResultSet authorNames = statement.executeQuery(sql);
    while (authorNames.next()){
                             String Name = authorNames.getString("name");
    out.println(Name);
    catch (SQLException s)
    out.println("SQL Error<br>");
    catch (ClassNotFoundException err)
    out.println("Class loading error");
    %>
    </body>
    </html>
    Regds
    Vasi

  • What's wrong with my simple IO code?

    import java.io.*;
    public class test4
    public static void main(String arg[])throws IOException
    File f=new File("u:/temp.txt");
    f.createNewFile();
    FileWriter fwriter=new FileWriter(f,true);     
    fwriter.write("can you see me?");
    }

    You have to close your, and you really should flush,
    your fwriter before sending any data to file:You mean after sending any data, right? ;)
    fwriter.flush();
    fwriter.close();I suppose it doesn't hurt to be explicit, but the flush() isn't strictly necessary as close() flushes the stream before closing it (as per the API docs). I'll leave it to you as to what level of verbosity you want.

Maybe you are looking for

  • Symbol does not clone properly

    I clone a symbol (button) and change its rollover color, but the other symbols (from wich this one was cloned) get updated... I need the new symbol to have unique rollover. This is Firesworks CS3 Thanx!.

  • Need help with java browser "Back" button

    All: I'm trying to make the "Back" button in my Java web browser work. Any help would be greatly appreciated. Here is my code: import javax.swing.*; import java.net.*; import java.awt.*; import java.awt.event.*; import javax.swing.event.*; import jav

  • Searching Secondary Indices as Inequalities Possible in Berkeley?

    I have a db with a secondary database on a date field, which is a string representation of unix time. I'm using the following function (in python) to find all keys greater than a specific time (for this example, the conversion function is something t

  • When you update Camera Raw do you need to update DNG converter too?

    I have Photoshop CS4 and wanted to update Camera Raw. I have forgoten if you need to update the DNG converter too or just leave it.  Im also looking for tutorials or " how to use" stuff for the new features  the lastest versions of Camera Raw (5.5 an

  • Renaming a tablespace through Datapump

    Hi. I have a tablespace X in my source and I want to import it in to another DB and rename it to Y VIA data pump. Do I have to use the REMAP_DATAFILE & REMAP_TABLESPACE parameters or will the REMAP_TABLESPACE do it for me? I my datafile has the name