Re: Probjems in communication with DB

Andreas Hartmann <[email protected]>
Newsgroups gmane.comp.cms.lenya.user
Message-ID <[email protected]>
Am 27.01.10 16:35, schrieb Gintare Ragaisiene:
> Hi,
>
>    I have problem with communication with my MySQL database. The problem
> is no inserted records in the db after INSERT close executed. When I
> connect with outside client to the same db and try to act it gives me
> "Lock wait timetout exceeded; try restart transaction". I have code :
>

>      protected void manageDbData(){
>          try {
>              ServiceSelector selector = (ServiceSelector)
> manager.lookup(DataSourceComponent.ROLE + "Selector");
>              this.datasource = (DataSourceComponent)
> selector.select("humana");
>              Connection myConnection = this.datasource.getConnection();
>              Statement stmt = myConnection.createStatement();
>
>              stmt.execute("INSERT INTO email VALUES (0, '[email protected]
> <mailto:[email protected]>')");
>
>              String query = "SELECT * FROM area";
>              ResultSet result = stmt.executeQuery(query);
>              System.out.println("EditNewsletters result =
> "+result.getFetchSize());

Is this code executed?

>
>              stmt.close();
>              myConnection.close();

I'm not too familiar with JDBC, but I'd assume that the close() 
statements should go into the finally clause to avoid exhaustion of the 
connection pool if exceptions occur.


BTW, your question is not really related to Lenya, maybe you get better 
hints on a more appropriate mailing list (e.g., on the Cocoon user list).

-- Andreas


-- 
Andreas Hartmann, CTO
BeCompany GmbH
http://www.becompany.ch
Tel.: +41 (0) 43 818 57 01
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.