Ask a Question related to Coldfusion Database Access, Design and Development.
-
xcles #1
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
-
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... -
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... -
[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... -
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... -
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... -
-
xcles #3
Re: java.sql sql exception
Error: java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 3.
xcles Guest
-
mxstu #4
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
-
xcles #5
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
-
xcles #6
Re: java.sql sql exception
and yes the fields i'm inserting to in Access are text fields....
xcles Guest
-
mxstu #7
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
-
xcles #8
Re: java.sql sql exception
yes, it does work......thank you so much
happy thanksgiving if you in Canada that is...
xcles Guest
-



Reply With Quote

