how to access database from a jsp page for searching

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • devi16mca
    New Member
    • Oct 2008
    • 1

    how to access database from a jsp page for searching

    how to access database from a jsp page
  • onlyshanks28
    New Member
    • Oct 2008
    • 13

    #2
    Hi try the following(do read the last paart on the post)
    [code=java]
    Connection myconn;
    String DbDriver = "org.gjt.mm.mys ql.Driver";
    String DbConStr = "jdbc:mysql ://localhost:3306/xyz";
    String DbUser ="root";
    String DbPwd ="abcdef";
    try {
    Class.forName(D bDriver);
    myconn = DriverManager.g etConnection(Db ConStr, DbUser,DbPwd);
    Statement mystat = myconn.createSt atement();
    ResultSet rs = mystat.executeQ uery("select title,link from sidebar");
    while (rs.next()) {%>



    <%
    String s1= rs.getString(1) ;
    String s2= rs.getString(2) ;
    out.println(s1) ;
    out.println(s2) ;
    %>
    catch(Exception e)
    {
    out.println("ex ception");
    }
    [/code]
    *************** *************** **********

    here the database I used is Mysql
    "xyz" is the name of the database
    "abcdef" is the password
    "root: is the user name..


    try this out and tell me the result...

    make sure to type the following in the starting of the code
    [code=html]
    <%@ page import =
    "java.sql.Conne ction,java.sql. DriverManager,j ava.sql.SQLExce ption, java.sql.Statem ent, java.sql.Result Set, java.util.*,jav a.io.*"
    %>
    [/code]
    Shashank(buz... ..............Z ZZZZZZZZZZZZZZZ ........)
    Last edited by Nepomuk; Oct 29 '08, 10:20 AM. Reason: Please use [CODE] tags

    Comment

    Working...