Re: Database and java.sql.SQLException Questions
- From: "Bjorn Abelli" <bjorn_abelli@xxxxxxxxxxxxxxxxxxxxx>
- Date: 27 Apr 2006 12:09:30 +0200
"zhah99 via JavaKB.com" wrote...
Well Integer was definitly one of my problems, I have the CreateDatabase
running now. I am working on the SalesClient. I am getting a
NullPointerException in the addNewSalesman method below. I think it might
have to do with the way I am inserting the data into the database, is this
correct? Am I do something wrong with the quotes?
Why not just test with some values, as if..
salesmanname = "John";
level = .15;
String insertsalesman2 = "INSERT INTO Salesman VALUES(" + salesmanname +
"," + "''" + level + ")";
....would become:
String insertsalesman2 =
"INSERT INTO Salesman VALUES(John,''.15)";
....which probably isn't what you want...
I would suggest you start using PreparedStatements instead, which would
simplify things, and make it a bit safer. That would insert those irritating
quotes by itself, and only when needed.
If I recall, a salesman really had three fields...
I expect you have your statements as instance variables somewehere else, so
if you continue with that solution, you could have them prebuilt there as
well...
=== in the class definition =======================
CallableStatement insertSalesmanStmt = null;
=== in the initalization code of the statements ===
String insertsalesman =
"INSERT INTO Salesman VALUES(?,?,?)";
insertSalesmanStmt =
connection.prepareCall (insertSalesman);
=== in addNewSalesman =============================
String name = ...
int id = ...
String type = ...
insertSalesmanStmt.setString(1, name);
insertSalesmanStmt.setInt(2, id);
insertSalesmanStmt.setString(3, type);
insertSalesmanStmt.execute();
===================================================
....unless you have changed the declaration of tables since before.
It would anyway show how you could approach it.
// Bjorn A
Inviato da X-Privat.Org - Registrazione gratuita http://www.x-privat.org/join.php
.
- References:
- Database and java.sql.SQLException Questions
- From: zhah99 via JavaKB.com
- Re: Database and java.sql.SQLException Questions
- From: Jon Martin Solaas
- Re: Database and java.sql.SQLException Questions
- From: zhah99 via JavaKB.com
- Re: Database and java.sql.SQLException Questions
- From: Bjorn Abelli
- Re: Database and java.sql.SQLException Questions
- From: zhah99 via JavaKB.com
- Database and java.sql.SQLException Questions
- Prev by Date: Re: UnsatisfiedLinkError
- Next by Date: Re: MSAccess get Query SQL source possible
- Previous by thread: Re: Database and java.sql.SQLException Questions
- Next by thread: Intersystems Cache' - Anyone use it?
- Index(es):