Discussions

Web tier: servlets, JSP, Web frameworks: how we create dsn in JSP with backend MySQL?

  1. how we create dsn in JSP with backend MySQL? (3 messages)

    hello every body.I am from delhi-india. I am developing a portal in JSP and backend as MySQL. At one point I am struck very seriously so need very urgent help from you as seen your message on java.sun.com. Can you tell me how how we create DSN in it and what is the syntex?An early help will be highly appreciated.with thanks & regards.
  2. Hi frnd here i am attaching u a sample page which uses dsn connection for jsp page

    <%@ page language="java" import="java.io.*, java.sql.*" %>
    <html>
    <head>
    <title>employee</title>
    </head>

    <body>
    <form name="frm1">
    <%

    try
       {
         Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    //employee the dsn name which connects to a database.

         Connection con = DriverManager.getConnection("jdbc:odbc:employee");
         Statement stmt = con.createStatement();
         Statement stmt1 = con.createStatement();
         stmt1.executeUpdate("insert into employee values(3,'khan')");
         out.println("Inserted");
         ResultSet rs = stmt.executeQuery("select * from employee");


    %>

    <TABLE border=1>
    <TR>
      
      <TD> &nbsp
        
         <SELECT NAME="select">
         <option>new</option>
         <% while(rs.next())
       {
       %>
       <OPTION><%=rs.getString(2)%></OPTION>
       <% } %>
      
            </SELECT>
      </TD>
      
      
      <TD align="right">
         <SELECT NAME="SEL1">
         <OPTION> NEW </OPTION>
         <% while(rs.next())
    {
    %>


    <OPTION><%=rs.getInt(1)%></OPTION>
    <% } %>
      
         </SELECT>
       </TD>
      
      
    </TR>

    </TABLE>

    <%

         
    // for(int i = 0 ; i<100; i++)
    // stmt1.executeUpdate("insert into employee (ename) values('"+i+" Record')");
         rs.close();

       }

       catch(Exception e)
       {
         out.println("message exception" + e.getMessage());
       }


    %>



    </form>
    </body>
    </html>
  3. Hi.

    Use driver =org.gjt.mm.mysql.Driver
    Protocol = jdbc:mysql:///Database_name
    Use this type 4 driver from www.caucho.com
    The documentation comes along with this driver.
    U need to add this driver to the system classpath

    Vijay Khanna
  4. You can get the MySQL driver here:
    http://mmmysql.sourceforge.net

    You can either add the jar to your classpath or put it in the lib directory of your jsp container.

    You can also use JNDI to lookup the driver by:

    InitialContext ic = new InitialContext();
    DataSource ds = (DataSource) ic.lookup(JNDI name of driver);
    Connection connnection = ds.getConnection();

    You should be able to setup the JNDI name for the driver in your container.