java.sql sql exception

Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default java.sql sql exception

    i get a run-time error anytime i run this code, could anyone help. it is an
    assignment due on monday and i have spent enough hours trying to figure out,
    but to no avail. it compiles okay by the way

    .......................................
    /* swing method getText gets name1,name2, and dept from GUI */

    String name1 = a.getText ( ) ;
    string name2 =b.getText ( ) ;
    String dept = c.getText ( ) ;

    // creates a new a new manager with 3 arguments
    Manager newManager = new Manager (name1, name2, dept) ;

    //java establish connection withn access database
    final String url = "jdbc:Odbc:EmployeeD" ;

    //WHERE THE PROGRAM CRASHES!!!! DOESNT LIKE name1,name2 and dept
    final String sSQL = "INSERT INTO Manager VALUES (name1,name2,dept)" ;


    try {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con = DriverManager.getConnection(url) ;
    Statement st = con.createStatement () ;
    int rec = st.executeUpdate(sSQL) ;
    System.out.println("Connection Successful!");
    st.close();
    con.close();
    }
    catch (ClassNotFoundException f ) {
    System.out.println("failed to load JDBC/ODBC driver");
    System.out.println("class error: " + f) ;
    }
    catch (SQLException f ) {
    System.out.println("Unable to connect");
    System.out.println("SQL Exception: " + f) ;
    }

    can anyone out there help cos i really dont want to spend thanksgiving (which
    is monday in canda) thinking about java and sql :)


    thanks

    xcles Guest

  2. Similar Questions and Discussions

    1. Java version Exception
      I have cold fusion version: 6,1,0,83762 and I am using j2sdk1.4.1_01 to build my java classes.....when I try to access the java classes..from cold...
    2. 500 Java bean field access exception. - Help me
      Hi, Brother?s, i have one problem, if i click in Settings in Serve Settings return the error: 500 Java bean field access exception. Java bean...
    3. [Flash Remoting MX]->java.lang.Exception
      Hi, I have a popup that calls a remoteObject (a cfc) and uses the results of two methods to populate comboboxes. My popup window also has a button...
    4. Coldfsuion + Java Instantiation Exception
      Hi, This is the error I am getting: An exception occurred when instantiating a java object. The cause of this exception was that: . when I...
    5. C# exception after calling Java/Axis web service
      I am calling a client's Java/Axis web service (I have no control over it's code). I added the WSDL no problem. When I call their method, I get an...
  3. #2

    Default Re: java.sql sql exception

    What is the exact error message?
    mxstu Guest

  4. #3

    Default Re: java.sql sql exception

    Error: java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 3.

    xcles Guest

  5. #4

    Default Re: java.sql sql exception

    The first problem is that the actual sql string sent to the database is


    .... I assume those are "text" fields, so access is complaining because the
    values aren't single quoted. The second problem is how you construct your sql
    statement. You're inserting the literal variable names ("name1", "name2",
    etc) not their values. In other words, you're attempting to execute this
    statement

    INSERT INTO Manager VALUES (name1,name2,dept)

    .... when I think you want something like this....

    INSERT INTO Manager VALUES ('john', 'jacob','sales');

    B) You're inserting the literal strings

    inserting the values of the variables 'name1', 'name2' and 'dept',

    mxstu Guest

  6. #5

    Default Re: java.sql sql exception

    thanks for the quick reply

    after trying your suggestions:

    INSERT INTO Manager VALUES ('name1', 'name2','dept') ;

    program no longer crashes, but name1, name2 and dept are literally copied into
    acess database rather than the stored value they hold.

    so i get name1,name2, and dept in my database rather than john,jacob and sales
    i typed in the GUI

    xcles Guest

  7. #6

    Default Re: java.sql sql exception

    and yes the fields i'm inserting to in Access are text fields....



    xcles Guest

  8. #7

    Default Re: java.sql sql exception

    No, that is not what I suggested. I was saying that is one of your problems...
    that you are inserting the literal names of the variables, not their values.
    It occurs because the java variables are enclosed within double quotes.

    final String sSQL = "INSERT INTO Manager VALUES (name1,name2,dept)";

    Create the string by concatenating the literal strings with the variable
    values. something like ...

    "INSERT INTO Manager VALUES ('"+ name1 +"','"+ name2 ( .... etc.....)



    mxstu Guest

  9. #8

    Default Re: java.sql sql exception

    yes, it does work......thank you so much

    happy thanksgiving if you in Canada that is...
    xcles Guest

  10. #9

    Default Re: java.sql sql exception

    Happy Thanksgiving to you too :-)
    mxstu Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139