Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlets connection

 
Kajol Shroff
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everybody,
I want to connect the database through servlets ...I have made the html pages ... now i donno how do I make the servlets connections...
Please help me out...as I am a beginner and am new to server side ...previously I was working on the client side...
Kajol
 
Harpal Singh
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kajol,
All u have to write is a JDBC code in ur servlets......
register the driver
connect to the database
and make the query and get the result set
tell me if u want the full code,
Harpal
 
Kajol Shroff
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Harpal,
Can u give me some example to do that....
That would be really nice...
Kajol
[This message has been edited by Kajol Shroff (edited June 06, 2001).]
 
maha anna
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kajol,
A very good sample from Sun's JDBC tutorial itself, Also try to read this tutorial. It is very good.
http://java.sun.com/products/jdk/1.1/docs/guide/jdbc/getstart/SimpleSelect.doc.html
regds
maha anna
 
Harpal Singh
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kajol,

maha anna has given an excellent link ....I think i need not provide u with an example.....maha at her best......as usual
Harpal
 
Kajol Shroff
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Maha,
The link was really helpfull to me.. and very much to the point ..thanks again...
Harpal thanks to you too...
Kajol
 
Rinku Sharma
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi kajol,
All u have to do is to write the JDBD code in ur service method of ur servlet.
The code follows:
private Connection con;Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc dbc:aadsn","scott","tiger");
Statement stmt=con.createStatement();
ResultSet rs= stmt.executeQuery("select * from tablename");
rs.close();
stmt.close();
con.close();
bye
amit
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic