Wrox Home  
Search P2P Archive for: Go

  Return to Index  

servlets thread: Connecting Java classes to get connection to database


Message #1 by "huma h" <humashaz@h...> on Mon, 04 Mar 2002 19:33:31 -0500
Hello Julian.I hate to bug you  again but I have some more confusion .I also 
have to create a database connection class through the bean.and make separte 
classes/objects for the database tables.Do I need to call the methods of 
each object which has the get and set method through the database connection 
class.Please do reply to me as the clouds of vagueness are hovering all over 
my mind .Your response to my first question is sincerely appreciated

Huma


>From: "Julian Catino" <jvmc@i...>
>Reply-To: "Servlets" <servlets@p...>
>To: "Servlets" <servlets@p...>
>Subject: [servlets] Re: Connecting Java classes to get connection to 
>database
>Date: Mon, 4 Mar 2002 22:47:34 -0300
>
>   ----- Original Message -----
>   From: huma h
>   To: Servlets
>   Sent: Monday, March 04, 2002 9:33 PM
>   Subject: [servlets] Connecting Java classes to get connection to 
>database
>
>   Hello Friends
>
>   I am new to Java/Servlet technology and need a little help.I have to 
>connect
>   database(SQL Server)tables through Java Classes which I presume will be
>   instansiated as Objects for each table through get and set methods .I am 
>a
>   little confused on this concept .Please if anyone out there has a good
>   understanding of the concept please can they help me out??
>
>   Any sample code would be welcomed as well??
>
>   Thanks in advance
>
>There are several ways to analize this question.
>If you want an object to represent each table in your DB schema, then you 
>could construct one object per table.
>For example, you could have two tables :
>     -> Clients
>     -> Products
>...and you could create two classes :
>     Client.java
>     Product.java
>which represents a client, and a product. In this way, you have an atomic 
>representation of your db model.
>
>But think about if you really want an atomic or an "business" model. May be 
>you want only a business representation, or a representation of your 
>SQL-business results.
>
>Each class may have one property per field in your table (a property such 
>as "clientName"), then you could have :
>
>     public class Client
>     {
>         private String name;
>
>...
>
>         /* a setter */
>         public void setName(String newValue)
>         {
>             this.name = newValue;
>         }
>         /* a getter */
>         public String getName()
>         {
>             return this.name;
>         }
>
>     }
>
>Then, you can hide a "name" implementation.
>May be you must think in a way like :
>     public class Client extends PersistentObject
>
>to reuse persistence's code.
>
>In JavaBeans technology, you can use classes like this "Client" class for 
>iteract with your db model.
>Read the JavaBeans tutorial in java.sun.com site or JavaBeans discussions 
>in jGuru site for more info.
>In a better way, you could create not JavaBeans as described here, but EJB 
>entity beans in a J2EE model.
>
>
>Julián Catino
>
>
>




_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com


  Return to Index