Thread: Urgent! JDBC connection fail -- first time succeed, second time fail

Urgent! JDBC connection fail -- first time succeed, second time fail

From
"Kitty"
Date:
Dear sir,
    I have downloaded the postgres jdbc driver to be run with Lotus Domino R5 in Red Hat Linux6.2.  I am using Postgres 6.5.3 and I have downloaded the file "jdbc6.5-1.2.jar".  I have used the following code to connect to the database. 
 
import lotus.domino.*;
import java.sql.*;
import java.util.Properties;
import java.util.Vector;
import lotus.domino.*;
import java.util.Enumeration;
 
public class agtSaveRecord extends AgentBase{
 
  Driver drv = null;
  public void NotesMain() {    
    try {
      Session session = getSession();
      AgentContext agentContext = session.getAgentContext();     
      Database db = agentContext.getCurrentDatabase();
      Document doc = agentContext.getDocumentContext();
 
  drv = (Driver) Class.forName("postgresql.Driver").newInstance();
  Connection con = DriverManager.getConnection("jdbc:postgresql://192.168.1.28:5432/notestest", "notes", "lotusnotes");
  Statement st = con.createStatement();
  String strSql;
 
  strSql = "INSERT INTO ktest VALUES ('" + doc.getItemValueString("txtUCN") +
           "', '" + doc.getItemValueString("txtSubject") +
               "', '" + doc.getItemValueString("txtContent") + "')";
  st.executeUpdate(strSql);
 
      st.close();
      con.close();
      // doc.remove(true);
    } catch(Exception ex) {
      System.out.println("Error problem!");
      System.out.println(ex.getMessage());
      ex.printStackTrace();
    } finally {
      try {
        Enumeration eDrivers = DriverManager.getDrivers();
        for (; eDrivers.hasMoreElements();) {
          System.out.println("Drivers not empty.");
          DriverManager.deregisterDriver((Driver) eDrivers.nextElement()); 
        }
  } catch (Exception e) { 
        e.printStackTrace();
      }
    }    
  }
}
 
I can succeed to connect to the database and insert the data into the database occasionally.
After that, I tried to run the program again, but it failed with the following error.
 
No suitable driver
 
java.sql.SQLException: No suitable driver
 
 at java.sql.DriverManager.getConnection(DriverManager.java:103)
 
 at java.sql.DriverManager.getConnection(DriverManager.java:126)
 
 at agtSearchRecord.NotesMain(agtSearchRecord.java:21)
 
 at lotus.domino.AgentBase.runNotes(AgentBase.java:160)
 
 at lotus.domino.NotesThread.run(NotesThread.java:203)
 
If after seeing this error, I will wait for around 5 mins and run the program again, and it will be ok.
It seems that the driver cannot be released out for use immediately.
Is it the problem of the driver or cause by some imcompability or anything else?
 
Regards,
Kitty Chan

Re: Urgent! JDBC connection fail -- first time succeed, second time fail

From
"Nick Fankhauser"
Date:
Kitty-

I've never heard of anything like this happening before. Your code looks
good to me.

If I were trying to debug this, I think I'd start by removing the lotus
portion to see if you get the error using plain jdbc & postgresql. Perhaps
this would yield a clue.

-Nick

--------------------------------------------------------------------------
Nick Fankhauser  nickf@ontko.com  Phone 1.765.935.4283  Fax 1.765.962.9788
Ray Ontko & Co.     Software Consulting Services     http://www.ontko.com/