Link to home
Start Free TrialLog in
Avatar of _Esam
_Esam

asked on

JDBC example to populate a regular bean from SQL Server 2000

Hi Experts,

I need a simple example to populate a regular bean with JDBC connections for SQL Server 2000.

I need to see what driver to load (I have Windows XP with Tomcat)
How to connect to the SQL Server.
How to populate the bean.

How to use the bean to output the properties of the bean in JSP.

I need a code snippet and a simple explanation.

Thank you.

Regards,

_Esam
Avatar of Kuldeepchaturvedi
Kuldeepchaturvedi
Flag of United States of America image

Well first you will have to create a Database Access Bean to start with.
I am assuming here that you are connecting to your SQL server over a JDBC-ODBC bridge

public class DbBean
{
Connection DataBCon;
Statement stmt;
public Statement connect()
{
try{
DataBDriver = (Driver)Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
DataBCon = DriverManager.getConnection("jdbc:odbc:bdsql");
stmt = DataBCon.createStatement();
return stmt;
}
catch(Exception e)
{
return null;
}
}
}


Now in your beans you can instanciate this class, get a statment and use it for data fetching
ASKER CERTIFIED SOLUTION
Avatar of bloodredsun
bloodredsun
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of _Esam
_Esam

ASKER

Hi,
Sorry for the late reply....but the accepted answer was exactly what I was looking for...

Excellent...

Thanks...

_Esam
Cheers _Esam :-)