Re: NullPointerException when trying to PreparedStament.setString()
Posted by: Tom Coupland
Date: September 15, 2005 08:02AM

Hi Mark,

Sorry for the lack of info, was just about to retifiy matters when you posted. Heres may driver and sql version numbers

ConnectorJ 3.1.10
MySql 4.1.10a-standard

I am trying to setup a system with JBoss so that i can have my preparred statments living in the JNDI where my other objects can get at and use them.

Originally i was creating the PreparredStatments when i was setting up my DataBaseAccess service which is basically working as an abstraction layer between my code and the actual MySQLDS service, this is because the final database has not yet been chosen. They where being created with the first Connection i got out of the MySQLDS pool, with the sql statement coming from a txt file. The code that created them is

new PersistentDatagram(datagramName,
dbConn.prepareStatement(tokener.nextToken(),Integer.parseInt(tokener.nextToken()),
Integer.parseInt(tokener.nextToken())));
}

The changes i made where so that i could define the preparredStatments in the service.xml file of JBoss, allowing me to change them at will. So now what happens is the DataBaseAccess service is setup and gets a test connection just to check everythings working properly, then it sits there waiting for work. I've made up a class to hold the prepared statement in the JNDI called persistentDatagram (gotta change that name!), which depends on the DataBaseAccess. So when the persistentDatagrams definition is reached it gets a handle on the DataBaseAccess service out of the JNDI and calls the following method from it

public PreparedStatement prepareStatment(String sql, int resultSetType, int resultSetConcurrency) throws SQLException{
Connection dbConn = null;
StringWriter datasourceLog = new StringWriter();
try{
datasource.setLogWriter(new PrintWriter(datasourceLog));
dbConn = datasource.getConnection();
return dbConn.prepareStatement(sql, resultSetType, resultSetConcurrency);
}finally{
log.info("Dump of datasource messages --> \n"+datasourceLog);
dbConn.close();
}
}

I've just added that log thingy, looking for clues, but no log entries are made to it at all. The returned statement is then housed in the PersistentDatagram and made availible in the JNDI.

Thats a brief explaination of whats going on, if you need more i can post the code if you like.

Thanks for your reply

Tom

Options: ReplyQuote


Subject
Written By
Posted
Re: NullPointerException when trying to PreparedStament.setString()
September 15, 2005 08:02AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.