• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

No Database Connection Pooling but still works

 
ajay vasudevan
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using Servlets only.
i made a connection to a sybase interactive sql thru a jdbc-odbc bridge.the coding is as follows...

Class.forName("sun.jdbc.odbc.JdbcObdcDriver");
Connection conn = java.sql.DriverManager.getConnection("jdbc dbc:myConn","dba","sql");

All the above coding is made inside a class and set as an attribute in ServletContext scope.
When data is to be stored into the database,i get the Connection via a method in the above class and make the corresponding insertions. i am not using any synchronized keyword anywhere. i used a simple name and email textbox page that in turn to be stored in the database.

my question is how the data is bound to individual thread/requests.why doesn't the data get interchanged or misplaced. like say A's email gets stored in as B's email and vice-versa.it just works fine under the blue.why and how?

please reply soon.

ajay vasudevan
scjp 1.4
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If conn is declared in a method, then the Connection object will only be used in a single thread. It would be unwise to declare conn as an instance variable or, even worse, as a class variable.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic