[b][u]JSP create mysql DataBase problem[/u][/b]

While i try to create mysql database through JSP program using query,
the qurey statement doesn't work
stmt.executeUpdate("create database employee;"); is not executing.
The code is as follows : Please Help Me......
try {
Connection con = null;
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/bedrock","Dude1","");
try {
Statement stmt=con.createStatement();
stmt.executeUpdate("create database employee;");
System.out.println("Statement Executed");
catch(Exception e) {
System.out.println("Statement not Executed");
catch (SQLException ex) {
while (ex != null) {
System.out.println("sql exception"+ex);
ex = ex.getNextException ();
" THANKS IN ADVANCE "

It's not common to create databases with Java. I'd say this is especially true of JSPs. You'll have to GRANT permission to access and create tables to every single user that comes in? Are those tables cleaned up when users are done, or does the number of tables grow as the number of users grows? One table per customer? Sounds more like session or cookies to me. Do you validate users to make sure that only authorized users can create tables? Lots of problems, and it doesn't appear that you've addressed any of this from the code you've posted.
It's a bad idea to have code like this in a JSP. Those are for view only. Better to put database code on the server side where it belongs.
%

Similar Messages

  • I can not create mysql database

    I installed mariadb and mariadb-client. Whent I type this in command line
    mysql> CREATE DATABASE menagerie;
    a text file was created which name is CREATE and it consist of mysql --help output.
    How can I create mysql database?

    I think the problem is that you took the instructions too literally. There's a system command line, and a MySQL command line; you're likely looking for the second.
    Try running in your terminal:
    $ mysql
    This will bring up a MySQL prompt that will look like:
    mysql>
    inside of which you can run your "CREATE DATABASE" command.

  • Jsp JST MySQL - database connection

    Hello
    I am facing a database connection problem. I want to connect to mysql database fro a jsp page that uses JSTL taglibs.
    I am using Tomcat 5.x, JSTL 1.1. MySQL 5x
    I have copied jstl.jar, standard.jar and mysql driver in the \WEB-INF\lib dir of my application.
    If I connect to the database using scriptlet it works. But If I connect using the sql taglib, it gives me the error
    2008-01-22 14:20:12 StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw exception
    javax.servlet.jsp.JspException: Unable to get connection, DataSource invalid: "java.sql.SQLException: No suitable driver"
    my jsp file is as follows
    <%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <c:set var="firstName">request.getParameter("name")</c:set>;
    <%= request.getParameter("name") %>
    <sql:setDataSource
    var="myDS"
    scope="request"
    driver="com.mysql.jdbc.Driver"
    url="jdbc:mysql://localhost:3306/contact_db"
    user="root"
    password=""
    />
    <sql:query var="phone_book" dataSource="$(myDS)">
    Select last_name, home, cell, office from phone_book where first_name = ?
    <sql:param value="firstName"/>
    </sql:query>
    <HTML>

    hi thanks
    please let me know whats the better approach for getting an database connection if this is not recommended.
    after some modifications i am not getting the no suitable driver error. I also updated the code as per your comments. ...yet am not seeing any results.
    I have modified the file as follows.
    <%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <%
    String firstName = request.getParameter("name");
    %>
    <%= firstName %>
    <sql:setDataSource
    var = "firstDS"
    scope="request"
    driver="com.mysql.jdbc.Driver"
    url="jdbc:mysql://localhost:3306/contact_db"
    user="root"
    password=""
    />
    <sql:query var="phone_book" dataSource="${firstDS}">
         Select * from phone_book where first_name = ?
         <sql:param value="${firstName}"/>
    </sql:query>
    <c:forEach var="phone_book" items="${user.rows}">
         <tr>
    <td><c:out value="${row.no}"/></td>
    <td><c:out value="${row.first_name}"/></td>
    <td><c:out value="${row.last_title}"/></td>
    <td><c:out value="${row.home}"/></td>
    <td><c:out value="${row.cell}"/></td>
    <td><c:out value="${row.office}"/></td>
    </tr>
    </c:forEach>
    <HTML>
    <BODY>
         Hello
    </BODY>
    </HTML>

  • JSP contacting MySQL database

    I want to make a simple Login page that queries a MySQL database. Can someone please tell me if they know of documentation that can take me through easily?

    Connection to any database is alike. Only the database drivers differs. If I am not wrong, this is the string to get connected to MySql database.
    Class.forName("org.gjt.mm.mysql.Driver");
    Connection con=DriverManager.getConnection("jdbc:mysql://200.200.200.200/xxxxxx","xxxxxx","xxxxx");
    where first xxxx is the dsn name, and the second xxxx is the userid and the third xxxx is the password to get connected to the mysql database.
    Hope it helps
    Uma
    http://www.javagalaxy.com

  • How to connect JSP with MySql Database?

    HI All...
    I want to know or How to connect Mysql with JSP or JSF any other software is available? please help me.....

    I want to know or How to connect Mysql
    with JSP or JSF any other software isavailable?
    please help me.....First you need to find 25 m of a CatV cable and...The DB files need to be located on the ninth device of a SCSI Daisy Chain with the total SCSI cable length being over 150 m (and the devices (and cables) need to be mix of Differential and Non-Differential).
    Edit: And forget the terminator, who needs it?

  • JSP & Crystal Reports Database Problem

    Hi all,
    I hava problem with refreshing the crystal report web viewer if the report retrieves data from DB.
    If I don't refresh the report, it shows the report with default parameters. But when I refresh the report (I mean viewer.refresh()) it gives an error which says it could not found the JNDI.
    Do you have any idea about it ???
    Thanks in advance.
    Ismail TURK.

    So it can't find the JNDI name.
    What JNDI name is it looking for?
    How are you connecting to the database in the Crystal Reports developer.
    How It works on my machine. [long spiel]
    For some reason I was never able to get a JNDI connection throught the CR10 developer. It kept giving me error messages. But I DID manage to connect to Oracle via the standard Oracle TNSNames interface.
    When I tried loading the report in the browser, it looked for a JNDI name the same as the TNSName. Dunno why.
    The issue is that Tomcat stores the JNDI datasources under java:/comp/env/.
    And I couldn't configure the report to look in that initial context.
    My hack of a solution: load the JNDI datasource myself, and then bind it into the place where Crystal Reports looked:
    So I had
    1 - a TNS Name entry called REPORT_DB which the report designer connected to
    2 - a JNDI entry REPORT_DB defined in Tomcat
    <%
    Context initContext = new InitialContext();
    System.out.println("binding");
    try{
    Object obj = initContext.lookup("REPORT_DB");
    catch(NamingException e){
      System.out.println("Naming exception " + e);
      Context envContext  = (Context)initContext.lookup("java:/comp/env");
      DataSource ds = (DataSource)envContext.lookup("REPORT_DB");
      initContext.bind("REPORT_DB", ds);
    System.out.println("bound");
    %>Maybe this might help you, maybe not.
    Cheers,
    evnafets

  • JSP with mysql database

    *********************This is my HTML form for Media search*****************
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN">
    <html>
    <head>
    <meta content="text/html; charset=ISO-8859-1"
    http-equiv="content-type">
    <title>search media form</title>
    </head>
    <body>
    <form name="search" action="med_search.jsp"> <big
    style="font-weight: bold; color: rgb(0, 102, 0);">Media
    : Search<br>
    </big>
    <hr
    style="height: 1px; width: 50%; margin-left: 0px; margin-right: auto;"><label>Media
    :   equals :</label><big
    style="font-weight: bold; color: rgb(0, 102, 0);">  
    <select size="1" name="msearch_name">
    <option>-All-</option>
    <option>100% Home Girls</option>
    <option>1800mumanddad</option>
    <option>2D Max</option>
    <option>Access all areas</option>
    <option>Adelaide Advertiser</option>
    <option>Adelaide Messenger</option>
    <option>Adelaide Sunday Mail TV guide</option>
    <option>All Media</option>
    <option>Ari Reserved</option>
    <option>Austar</option>
    <option>Blockbuster</option>
    <option>Brisbane Courier Mail</option>
    <option>Brisbane Quest</option>
    <option>Brisbane Sunday Mail- TV guide</option>
    <option>Cleo</option>
    <option>Community</option>
    <option>Cosmo</option>
    <option>Day Time TV</option>
    <option>Dolly</option>
    <option>Edge</option>
    <option>Empire</option>
    <option>EMS</option>
    <option>Explode</option>
    <option>Facing Sanity</option>
    <option>Fairfax</option>
    <option>FHM</option>
    <option>Foxtel</option>
    <option>Funkysexycool</option>
    <option>Gametel newsletter</option>
    <option>Gametel Sim Pack</option>
    <option>Gametel UI 1st Version</option>
    <option>Gametel UI 2nd Version</option>
    <option>Gametel Website</option>
    <option>Geelong Advertiser-TV guide</option>
    <option>Girlfriend</option>
    <option>Good Medicine</option>
    <option>Herald Sun</option>
    <option>Home Girls</option>
    <option>Insight</option>
    <option>MailBlast</option>
    <option>Maximum Performance</option>
    <option>Melboume Leader</option>
    <option>Mobile</option>
    <option>Mobile Pet-Ari</option>
    <option>Money Saver</option>
    <option>Motor Show Mag</option>
    <option>Mr.Wisdoms Whopper</option>
    <option>MTV</option>
    <option>Music Australia</option>
    <option>New Chat</option>
    <option>New Idea</option>
    <option>NW Magazine</option>
    <option>One Love</option>
    <option>Optus</option>
    <option>Penthouse</option>
    <option>People</option>
    <option>Picture</option>
    <option>Picture Premium Edition</option>
    <option>Picture Premium Special</option>
    <option>Platinum Girls</option>
    <option>Phychic Business Cards</option>
    <option>Phychic Calender</option>
    <option>Phychic CD Cover</option>
    <option>Ralph</option>
    <option>Sain Magazine</option>
    <option>Sanity Chart</option>
    <option>Series 40 gametel subscriber</option>
    <option>Series 60 gametel community</option>
    <option>Series 60 gametel non-subscriber</option>
    <option>Series40 non-subscriber</option>
    <option>Smash Hits</option>
    <option>SMS Chat</option>
    <option>Soap World</option>
    <option>SPAM</option>
    <option>STM-WA</option>
    <option>Stupid People Line</option>
    <option>Sunday Herald Sun TV guide</option>
    <option>Sunday Telegraph TV guide</option>
    <option>Sunday Times TV guide</option>
    <option>Sydney Cumberland</option>
    <option>Sydney Daily telegraph</option>
    <option>Take 5</option>
    <option>Tasmania TV guide</option>
    <option>That's Life</option>
    <option>Total Gamer</option>
    <option>TV 10</option>
    <option>TV 7</option>
    <option>TV 9</option>
    <option>TV Hits</option>
    <option>TV Soap</option>
    <option>TV Week</option>
    <option>UNASSIGNED</option>
    <option>Urban Hits</option>
    <option>VH1</option>
    <option>Video Ezy</option>
    <option>Vogue Girl</option>
    <option>WAP</option>
    <option>Web Competitions</option>
    <option>Website</option>
    <option>West Magazine</option>
    <option>Western Australian</option>
    <option>What DVD</option>
    <option>What's Hot on Video</option>
    <option>Witchcraft</option>
    <option>Women's Day</option>
    <option>xxx</option>
    </select>
    <br>
    <span style="font-weight: bold;"><span
    style="color: rgb(0, 102, 0);"><span
    style="font-weight: bold;"><span
    style="font-weight: bold;"></span></span></span></span></big><big
    style="font-weight: bold; color: rgb(0, 102, 0);">  
          </big><big
    style="color: rgb(0, 102, 0);"><small><label
    style="color: rgb(0, 0, 0);">or
    is like :</label></small></big><big
    style="font-weight: bold; color: rgb(0, 102, 0);">  
    <textarea cols="20" rows="1" name="msearch_like"></textarea><br>
         </big><label
    style="color: rgb(0, 0, 0);">Media Type
    :</label><big style="font-weight: bold; color: rgb(0, 102, 0);">
    <select size="1" name="msearch_type">
    <option>-All-</option>
    <option>magazine</option>
    <option>newspaper</option>
    <option>other</option>
    <option>tv</option>
    <option>tv guide</option>
    </select>
    <br>
    <br>
    </big> <input name="med_search" value="Search"
    type="submit">  <input name="med_reset"
    value="Reset" type="reset"></form>
    <br>
    <br>
    </body>
    </html>
    //After clicking search button it will go to this jsp and gets the searched records.
    ***********************************med_search.jsp***********************
    <html>
    <body>
    <h1>Search Media</h1>
    <%@page contentType="text/html"%>
    <%@page pageEncoding="UTF-8"%>
    <%--
    The taglib directive below imports the JSTL library. If you uncomment it,
    you must also add the JSTL library to the project. The Add Library... action
    on Libraries node in Projects view can be used to add the JSTL 1.1 library.
    --%>
    <%--
    <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    --%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <%@ page import="java.sql.*" %>
    <% Connection con=null;%>
    <% PreparedStatement pstmt=null;%>
    <%
    try
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    con = DriverManager.getConnection("jdbc:mysql://silverbullet:3306/elmophish", "sirisha", "gametel123");
    out.println("<table border=0>");
    if(request.getParameter("msearch_name").equals("-All-")&request.getParameter("msearch_type").equals("-All-"))
    %>
    <jsp:forward page="med_search.html"/>
    <%
    else if(!(request.getParameter("msearch_name").equals("-All-"))&!(request.getParameter("msearch_type").equals("-All-")))
    pstmt=con.prepareStatement("select media.media_name,media.media_code,media_types.media_type,media_genders.media_gender,media.target_age,publishers.publisher,media.is_bookable,media_id from media,media_types,media_genders,publishers where media_name in (select media_name from media where media_type_id in (select media_type_id from media_types where media_type=" + "'" + request.getParameter("msearch_type") + "'" +") and media.media_name =" + "'" + request.getParameter("msearch_name") +"'" + ")and media.media_type_id=media_types.media_type_id and media.target_gender_id=media_genders.media_gender_id and media.publisher_id=publishers.publisher_id");
    out.println("<th></th><th><b>Name</b>&nbsp</th><th><b>Code</b>&nbsp</th><th><b>Type</b>&nbsp</th><th><b>Gender</b>&nbsp</th><th><b>Age</b>&nbsp</th><th><b>Publisher</b>&nbsp</th><th><b>Active</b>&nbsp</th>");
    else if(!(request.getParameter("msearch_name").equals("-All-"))&&(request.getParameter("msearch_type").equals("-All-")))
    pstmt=con.prepareStatement("select media_name,media_code,media_type,media_gender,target_age,publisher,is_bookable,media_id from media me inner join media_types mt on me.media_type_id = mt.media_type_id inner join media_genders mg on mg.media_gender_id = me.target_gender_id inner join publishers pub on pub.publisher_id = me.publisher_id where media_name="+"'"+request.getParameter("msearch_name")+"'"+"") ;
    out.println("<th></th><th><b>Name</b>&nbsp</th><th><b>Code</b>&nbsp</th><th><b>Type</b>&nbsp</th><th><b>Gender</b>&nbsp</th><th><b>Age</b>&nbsp</th><th><b>Publisher</b>&nbsp</th><th><b>Active</b>&nbsp</th>");
    else if(request.getParameter("msearch_name").equals("-All-")&!(request.getParameter("msearch_type").equals("-All-")))
    pstmt=con.prepareStatement("select media_name,media_code,media_type,media_gender,target_age,publisher,is_bookable,media_id from media me inner join media_types mt on me.media_type_id = mt.media_type_id inner join media_genders mg on mg.media_gender_id = me.target_gender_id left join publishers pub on pub.publisher_id = me.publisher_id where media_type=" + "'"+request.getParameter("msearch_type")+"'"+"");
    out.println("<th></th><th><b>Name</b>&nbsp</th><th><b>Code</b>&nbsp</th><th><b>Type</b>&nbsp</th><th><b>Gender</b>&nbsp</th><th><b>Age</b>&nbsp</th><th><b>Publisher</b>&nbsp</th><th><b>Active</b>&nbsp</th>");
    ResultSet rst=pstmt.executeQuery();
    ResultSetMetaData rsmd=rst.getMetaData();
    int n=rsmd.getColumnCount();
    while(rst.next())
    out.println("<tr>");
    %>
    <td><form action="test.jsp" method="post"> <a href="t.jsp?media_id=<% out.print(rst.getString(8)); %>">Edit</a></form></td>
    <%
    out.print("<td>"+rst.getString(1)+"</td>");
    out.print("<td>"+rst.getString(2)+"</td>");
    out.print("<td>"+rst.getString(3)+"</td>");
    out.print("<td>"+rst.getString(4)+"</td>");
    out.print("<td>"+rst.getString(5)+"</td>");
    out.print("<td>"+rst.getString(6)+"</td>");
    out.print("<td>"+rst.getString(7)+"</td>");
    out.print("</tr>");
    }catch(Exception e)
    out.println(e);
    finally
    con.close();
    %>
    <%--
    This example uses JSTL, uncomment the taglib directive above.
    To test, display the page like this: index.jsp?sayHello=true&name=Murphy
    --%>
    <%--
    <c:if test="${param.sayHello}">
    <!-- Let's welcome the user ${param.name} -->
    Hello ${param.name}!
    </c:if>
    --%>
    </body>
    </html>
    //In this search output we have edit button for each row.After we click search it will enter into another form where we can edit the record.
    //In this jsp,i have designed the form for editing and displayed the current record values as initial values and after edit it must save and update the DB.But before I click save changes,its updating the DB with all zeros.
    ******************edit_search.jsp**************************************
    <%@page contentType="text/html"%>
    <%@page pageEncoding="UTF-8"%>
    <%--
    The taglib directive below imports the JSTL library. If you uncomment it,
    you must also add the JSTL library to the project. The Add Library... action
    on Libraries node in Projects view can be used to add the JSTL 1.1 library.
    --%>
    <%--
    <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    --%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <h1>Edit Search</h1>
    </head>
    <body>
    <%@ page import="java.sql.*" %>
    <% Connection con=null;%>
    <% String str1,str2,str3,str4,str5,str6;%>
    <%
    try
    int mgid=0;
    int tage=0;
    int pid=0;
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    con = DriverManager.getConnection("jdbc:mysql://silverbullet:3306/elmophish", "sirisha", "gametel123");
    PreparedStatement pstmt=con.prepareStatement("SELECT media_name,media_code,media_type,media_gender,target_age,publisher,is_bookable FROM media m INNER JOIN media_types met ON m.media_type_id = met.media_type_id INNER JOIN media_genders meg ON m.target_gender_id = meg.media_gender_id LEFT JOIN publishers pubs ON m.publisher_id = pubs.publisher_id where media_id=" + "'"+request.getParameter("media_id")+"'");
    ResultSet rs=pstmt.executeQuery();
    ResultSetMetaData rsmd=rs.getMetaData();
    int n=rsmd.getColumnCount();
    while(rs.next())
    %>
    <form method="post" action="">
    <label>Name</label> <%=rs.getString("media_name")%><br>
    <label>Code</label> <textarea cols="20" rows="1"name="med_code"><%=rs.getString("media_code")%></textarea><br>
    <label>Type</label> <%=rs.getString("media_type")%><br>
    <label>Target Gender</label>&nbsp
    <% PreparedStatement pstmt2=con.prepareStatement("SELECT media_gender FROM media_genders");
    ResultSet rst1=pstmt2.executeQuery();
    ResultSetMetaData rstmd2=rst1.getMetaData();
    int cnt1=rstmd2.getColumnCount();
    %>
    <select name="tar_gen">
    <%
    while(rst1.next())
    %>
    <option><%=rst1.getString("media_gender")+"<br>"%></option>
    <%
    %>
    </select><br>
    <label>Target Age</label> <textarea cols="20" rows="1" name="med_age"><%=rs.getString("target_age")%></textarea><br>
    <label>Publisher</label> 
    <%
    PreparedStatement pstmt1=con.prepareStatement("SELECT publisher FROM publishers");
    rst1=pstmt1.executeQuery();
    ResultSetMetaData rstmd1=rst1.getMetaData();
    int cnt2=rstmd1.getColumnCount();
    %>
    <select name="pub">
    <%
    while(rst1.next())
    %>
    <option><%=rst1.getString("publisher")+"<br>"%></option>
    <%
    %>
    </select><br>
    <label>Bookable</label> 
    <input type="checkbox">
    <%
    if (rs.getString("is_bookable").equals("1"))
    %>
    <checkbox maxlength="20" <checked></checkbox>
    <%
    else
    %>
    <checkbox maxlength="20" <unchecked></checkbox>
    <%
    %>
    <%
    str1=request.getParameter("med_code");
    PreparedStatement pst2=con.prepareStatement("select media_gender_id from media_genders where media_gender = "+ "'" + request.getParameter("med_gen") +"'");
    ResultSet rst2=pst2.executeQuery();
    while(rst2.next())
    mgid=rst2.getInt(1);
    rst2.close();
    str2=request.getParameter("med_gen");
    try
    tage=Integer.parseInt("'"+request.getParameter("med_age")+"'");
    catch(NumberFormatException e){}
    PreparedStatement pst3=con.prepareStatement("select publisher_id from publishers where publisher = "+ "'" + request.getParameter("pub")+"'");
    ResultSet rst3=pst3.executeQuery();
    ResultSetMetaData rsmd3=rst3.getMetaData();
    int nnn=rsmd3.getColumnCount();
    while(rst3.next())
    pid=rst3.getInt(1);
    rst3.close();
    //str4=request.getParameter("pub");
    try
    if(request.getParameter("bookable").equals("true"))
    str5="1";
    }catch(Exception e)
    str5="0";
    //str5=request.getParameter("bookable"");
    %><input name="med_edit" value="Save Changes" type="submit"><br></form>
    <%
    //out.println("<h2>2"+str1+"</h2>");
    PreparedStatement pstmt3=con.prepareStatement("UPDATE media set media_code="+str1+",target_gender_id="+mgid+",target_age="+tage+",publisher_id="+pid+" WHERE media_id="+"'"+request.getParameter("media_id")+"'");
    pstmt3.executeUpdate();
    //ResultSet res=.updateRow();
    //out.println("<h2>3"+str1+"</h2>");
    }catch(Exception e)
    out.println(e);
    finally
    con.close();
    %>
    <%--
    This example uses JSTL, uncomment the taglib directive above.
    To test, display the page like this: index.jsp?sayHello=true&name=Murphy
    --%>
    <%--
    <c:if test="${param.sayHello}">
    <!-- Let's welcome the user ${param.name} -->
    Hello ${param.name}!
    </c:if>
    --%>
    </body>
    </html>
    //This is another jsp which i replaced for edit_search.jsp.Functionality is same.And also giving the same result.But this is some what clear than edit_search.jsp.
    ****************************test.jsp******************************
    <%@page contentType="text/html"%>
    <%@page pageEncoding="UTF-8"%>
    <%--
    The taglib directive below imports the JSTL library. If you uncomment it,
    you must also add the JSTL library to the project. The Add Library... action
    on Libraries node in Projects view can be used to add the JSTL 1.1 library.
    --%>
    <%--
    <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    --%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>
    </head>
    <body>
    <%@ page import="java.sql.*" %>
    <% Connection con=null;%>
    <% String str1=null;
    String str2=null;
    String str3=null;
    String mgid=null;
    String tage=null;
    String pid=null;
    %>
    <%
    try
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    con = DriverManager.getConnection("jdbc:mysql://silverbullet:3306/elmophish", "sirisha", "gametel123");
    PreparedStatement pstmt=con.prepareStatement("SELECT media_name,media_code,media_type,media_gender,target_age,publisher,is_bookable FROM media m INNER JOIN media_types met ON m.media_type_id = met.media_type_id INNER JOIN media_genders meg ON m.target_gender_id = meg.media_gender_id LEFT JOIN publishers pubs ON m.publisher_id = pubs.publisher_id where media_id=" + "'"+request.getParameter("media_id")+"'");
    ResultSet rs=pstmt.executeQuery();
    while(rs.next()){
    %>
    <form method="post" action="">
    <label>Name</label> <%=rs.getString("media_name")%><br>
    <label>Code</label> <textarea cols="20" rows="1"name="med_code"><%=rs.getString("media_code")%></textarea><br>
    <label>Type</label> <%=rs.getString("media_type")%><br>
    <label>Target Gender</label>&nbsp
    <% PreparedStatement pstmt1=con.prepareStatement("SELECT media_gender FROM media_genders");
    ResultSet rst1=pstmt1.executeQuery();
    %>
    <select name="tar_gen">
    <%
    while(rst1.next())
    %>
    <option><%=rst1.getString("media_gender")%></option>
    <%
    %>
    </select><br>
    <label>Target Age</label> <textarea cols="20" rows="1" name="med_age"><%=rs.getString("target_age")%></textarea><br>
    <label>Publisher</label> 
    <%
    PreparedStatement pstmt2=con.prepareStatement("SELECT publisher FROM publishers");
    ResultSet rst2=pstmt2.executeQuery();
    %>
    <select name="pub">
    <%
    while(rst2.next())
    %>
    <option><%=rst2.getString("publisher")%></option>
    <%
    %>
    </select><br>
    <label>Bookable</label> 
    <input type="checkbox">
    <%
    if (rs.getString("is_bookable").equals("1"))
    %>
    <checkbox maxlength="20" <checked></checkbox>
    <%
    else
    %>
    <checkbox maxlength="20" <unchecked></checkbox>
    <%
    str1=request.getParameter("med_code");
    PreparedStatement pstmt3=con.prepareStatement("select media_gender_id from media_genders where media_gender = "+ "'" + request.getParameter("med_gen") +"'");
    ResultSet rst3=pstmt3.executeQuery();
    while(rst3.next()){
    mgid=rst3.getString("media_gender_id");
    rst3.close();
    try
    tage=request.getParameter("med_age");
    catch(NumberFormatException e){}
    PreparedStatement pstmt4=con.prepareStatement("select publisher_id from publishers where publisher = "+ "'" + request.getParameter("pub")+"'");
    ResultSet rst4=pstmt4.executeQuery();
    while(rst4.next()){
    pid=rst4.getString("publisher_id");
    rst4.close();
    try
    if(request.getParameter("bookable").equals("true"))
    str3="1";
    catch(Exception e)
    str3="0";
    %>
    <input type="submit" value="Save Changes"><br></form>
    <%
    PreparedStatement pstmt5=con.prepareStatement("UPDATE media set media_code="+str1+",target_gender_id="+mgid+",target_age="+tage+",publisher_id="+pid+",is_Bookable="+str3+" WHERE media_id="+"'"+request.getParameter("media_id")+"'");
    pstmt5.executeUpdate();
    out.println("123"+"media_code"+str1+" gender"+mgid+"....age.."+tage+"publisher_id="+pid+" is_Bookable="+str3);
    catch(Exception e)
    out.println("ttttttttttt");
    out.println(e);
    finally
    con.close();
    %>
    <%--
    This example uses JSTL, uncomment the taglib directive above.
    To test, display the page like this: index.jsp?sayHello=true&name=Murphy
    --%>
    <%--
    <c:if test="${param.sayHello}">
    <!-- Let's welcome the user ${param.name} -->
    Hello ${param.name}!
    </c:if>
    --%>
    </body>
    </html>
    *********************************************************************

    I want to know or How to connect Mysql
    with JSP or JSF any other software isavailable?
    please help me.....First you need to find 25 m of a CatV cable and...The DB files need to be located on the ninth device of a SCSI Daisy Chain with the total SCSI cable length being over 150 m (and the devices (and cables) need to be mix of Differential and Non-Differential).
    Edit: And forget the terminator, who needs it?

  • Create MySQL database for WordPress on Leopard - How to?

    Hi, folks.
    I've been trying to install WordPress using this tutorial http://www.tech-recipes.com/rx/2757/leopardhow_to_installwordpress/ but I've been facing two major problems:
    1. I can't find the hidden file .profile - I have already used TextWrangler to browse though my folders and I still couldn't find it.
    2. No Terminal command mentioned in the file seems to work. All of them return error messages.
    Could anyone help me to figure this out or simply tell me an easier way to install WordPress on Leopard?
    Cheers.
    JP

    1. I can't find the hidden file .profile - I have already used TextWrangler to browse though my folders and I still couldn't find it.
    It's entirely possible, and valid, for there to be no ~/.profile.
    If that's the case, just create it.
    2. No Terminal command mentioned in the file seems to work. All of them return error messages.
    Can you give an example, including the error message. The error message will go a long way to explaining why it didn't work.

  • JSP, EJB in Jboss 4 with mySQL database. Error in connecting to database

    Hi, i using JBoss 4-0-1 with jsp and mySQL database. I get this example from a book using stateless session beans. However i modify it so it can connect to mySQL database.
    This is my code for jsp.
    <%@ page import="asg.MusicEJB.*,
    java.util.*,
    javax.naming.Context,
    javax.naming.InitialContext,
    javax.rmi.PortableRemoteObject" errorPage="error.jsp" %>
    <%--
         The following 3 variables appear in a JSP declaration.
         They appear outside the generated _jspService() method,
         which gives them class scope.
         Since we want to initialize our Music EJB object once
         and read the Music Collection database to get the
         recording titles once, we place this code inside
         method jspInit().
         The EJB business method getMusicList()
         returns a collection of RecordingVO objects which we
         store in ArrayList albums.
    --%>
    <%!
         MusicHome musicHome;
         Music mymusic;
         ArrayList albums;
         Properties properties=new Properties();
         public void jspInit() {
                   properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
                   properties.put(Context.PROVIDER_URL, "localhost:3306");
                   System.out.println("............................in properties");
              try {
                   //Context initial = new InitialContext();
                   InitialContext jndiContext = new InitialContext(properties);
                   //Object ref  = jndiContext.lookup("MusicEJB");
                   Object objref = jndiContext.lookup("java:comp/env/ejb/EJBMusic");
                   musicHome = (MusicHome)PortableRemoteObject.narrow(objref, MusicHome.class);
                   mymusic = musicHome.create();
                   albums = mymusic.getMusicList();
                   System.out.println(".............................in line 64");
              } catch (Exception ex) {
                   System.out.println("Unexpected Exception............: " +
                             ex.getMessage());
                   ex.printStackTrace();
    %>
    <%--
         The following scriptlet accesses the implicit
         request object to obtain the current URL
         and saves it to the session object for later retrieval. 
         It also saves variable mymusic, so we can
         make remote calls to our Music EJB, and the collection of
         RecordingVO objects.  These variables will all be available
         to other pages within the session.
    --%>
    <%
         String requestURI = request.getRequestURI();
         session.putValue("url", requestURI);
         session.putValue("mymusic", mymusic);
         session.putValue("albums", albums);
    %>
    <html>
    <head>
    <title>Music Collection Database Using EJB & JSP Version 9.7</title>
    </head>
    <body bgcolor=white>
    <h1><b><center>Music Collection Database Using EJB & JSP</center></b></h1>
    <hr>
    <p>
    There are <%= albums.size() %> recordings.
    <form method="post" action="musicPost.jsp">
    <p>
    Select Music Recording:
    <select name="TITLE">
    <%
         // Generate html <option> elements with the recording
         // titles stored in each RecordingVO element.
         // Obtain the current title from the session object
         // (this will be null the first time).
         String title;
         String currentTitle = (String)session.getValue("curTitle");
         if (currentTitle == null) currentTitle = "";
         RecordingVO r;
         Iterator i = albums.iterator();
         while (i.hasNext()) {
              r = (RecordingVO)i.next();
              title = r.getTitle();
              if (title.equals(currentTitle)) {
                   out.println("<option selected>" + title + "</option>");
              else {
                   out.println("<option>" + title + "</option>");
    %>
    </select><p><p>
    <%--
         Provide a "View Tracks" button to submit
         the requested title to page musicPost.jsp
    --%>
    <input TYPE="submit" NAME="View" VALUE="View Tracks">
    </form>
    </body>
    </html>Message was edited by:
    chongming

    This is the deployment descriptor for the .ear file.
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE application PUBLIC '-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN' 'http://java.sun.com/dtd/application_1_3.dtd'>
    <application>
      <display-name>MusicDAOApp</display-name>
      <description>Application description</description>
      <module>
        <web>
          <web-uri>war-ic.war</web-uri>
          <context-root>music</context-root>
        </web>
      </module>
      <module>
        <ejb>ejb-jar-ic.jar</ejb>
      </module>
    <!--
      <module>
        <java>app-client-ic.jar</java>
      </module>
    -->
    </application>
    And this is the deployment for the ejb class files:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE ejb-jar PUBLIC '-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN' 'http://java.sun.com/dtd/ejb-jar_2_0.dtd'>
    <ejb-jar>
      <display-name>MusicEJB</display-name>
      <enterprise-beans>
        <session>
          <display-name>MusicEJB</display-name>
          <ejb-name>MusicEJB</ejb-name>
          <home>asg.MusicEJB.MusicHome</home>
          <remote>asg.MusicEJB.Music</remote>
          <ejb-class>asg.MusicEJB.MusicBean</ejb-class>
          <session-type>Stateless</session-type>
          <transaction-type>Bean</transaction-type>
          <env-entry>
            <env-entry-name>MusicDAOClass</env-entry-name>
            <env-entry-type>java.lang.String</env-entry-type>
            <env-entry-value>asg.MusicEJB.MusicDAOCloudscape</env-entry-value>
          </env-entry>
         <env-entry>
         <env-entry-name>dbUrl</env-entry-name>
            <env-entry-type>java.lang.String</env-entry-type>
            <env-entry-value>jdbc:mysql://localhost/music</env-entry-value>
          </env-entry>
          <env-entry>
            <env-entry-name>dbUserName</env-entry-name>
            <env-entry-type>java.lang.String</env-entry-type>
            <env-entry-value>chongming</env-entry-value>
          </env-entry>
          <env-entry>
            <env-entry-name>dbPassword</env-entry-name>
            <env-entry-type>java.lang.String</env-entry-type>
            <env-entry-value>kcm82</env-entry-value>
         </env-entry>
          <security-identity>
            <description></description>
            <use-caller-identity></use-caller-identity>
          </security-identity>
        </session>
      </enterprise-beans>
    </ejb-jar>I can combine the jar and war files into a ear file. deploying is alright without any errors.
    However when i run the jsp, it prompt this error:
    You Have Encountered an Error
    Stack Trace
    java.lang.NullPointerException
         at org.apache.jsp.musicGet_jsp._jspService(org.apache.jsp.musicGet_jsp:111)
         at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
         at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
         at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
         at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
         at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
         at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
         at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
         at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
         at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:159)
         at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
         at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
         at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
         at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
         at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
         at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
         at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
         at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
         at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
         at java.lang.Thread.run(Thread.java:595)
    How to i solve the error? I look at he catch results in the command prompt of JBoss , i found that when running, the code will be caught by the exception and display this:int.java:527)
    at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWor
    kerThread.java:112)
    at java.lang.Thread.run(Thread.java:595)
    13:55:21,375 INFO [STDOUT] Unexpected Exception............: EJBException:; nes
    ted exception is:
    javax.ejb.EJBException: getMusicList: SQLException during DB Connection:
    The url cannot be null
    13:55:21,375 INFO [STDOUT] java.rmi.ServerException: EJBException:; nested exce
    ption is:
    javax.ejb.EJBException: getMusicList: SQLException during DB Connection:
    The url cannot be null 13:55:21,375 INFO[STDOUT] at org.jboss.ejb.plugins.LogInterceptor.handleException(LogInterceptor.java:352)
    13:55:21,375 INFO [STDOUT] at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:196)
    What can i do to solve the problem? please helpMessage was edited by:
    chongming
    Message was edited by:
    chongming
    Message was edited by:
    chongming

  • Unable to connect JSP and MySQL

    Hi, I am new to this forum
    I've started developing web pages using JSP
    I've the problem connecting JSP and MySQL database. I've created the page that retrive records from mysql table. But the connection fail to access to database it gives me this error:
    org.apache.jasper.JasperException: Exception in JSP: /retreive_book.jsp:15
    The code is:
    12: <%
    13: //Class.forName("com.mysql.jdbc.Driver").newInstance();
    14: Class.forName("org.gjt.mm.mysql.Driver");
    15: connection = DriverManager.getConnection(connectionURL,"","");
    16: statement = connection.createStatement();
    17: rs = statement.executeQuery("SELECT * FROM books_detail");
    18: %>
    And the connectionURL parameter has this value:
    String connectionURL = "jdbc:mysql://localhost:3306/books?username=;password=";
    root cause msg is:
    java.sql.SQLException: Invalid authorization specification: Access denied for user 'nobody'@'localhost' (using password: NO)
    Please can anyone help me. It is 3 days now trying to do that but not succeded yet

    Hi
    Yes It is true that my MySQl installation its username is root. So how should put that in the url. Cause I did that but it didn.t work
    String connectionURL= "jdbc:mysql://localhost:3306/books?username=root;password=";
    If I write in that manner is it correct for root username or should I put a single quote
    Thanks

  • Mysql database issue

    Hi all,
    Please am a newbie when it comes to php and forms, I have created a site with a registration and login forms and I have equally created mysql database and table for the form inside mysql server but I need the database to take the data from the registration form and store it, and at the same time when the user login it will bring the their data to them. But I don't know how to connect it with form on my site and have it on my rootfolder/local server.  I will really appreciate if anyone can help out.

    I guess you should install Apache server. Then you configure your server with php and mysql with php.
    After that you can access your form from localhost url which will make a call to ur db and return you output. Hope it helps..
    Thanks,
    Ashish
    website: http://www.wikiuncle.com

  • How to create a database dynamically

    I am trying to create mysql database dynamically through java. Also please help me how to execute *.sql file in java.

    dheerajsea123 wrote:
    I am trying to create mysql database dynamically through java. Also please help me how to execute *.sql file in java.If possible it depends on the database and driver.
    If possible the exact methodology varies by database (driver shouldn't matter.)
    Normally it is not considered a good practice for traditional server applications.

  • MySQL database unavailable

    I've tried creating MySQL databases to no avail. I've done it within the Web App/MySQL template which always shows the db as unavailable and done it stand-alone. Both of which appear to create the db (ClearDB verified it was there and functional), but I
    can't do anything with them. Going into the stand-alone instance blade, the tiles just continually spin the loading dots. I have no idea what else to try. I have a couple dozen clients I'm trying to move up to Azure and this is a deal-breaker right now.
    Thanx for any help.
    -George Handlin

    Hi,
    I suggest you to follow the below Stackoverflow Thread 
    http://stackoverflow.com/questions/12190067/how-to-manage-mysql-databases-created-in-azure
    Hope this helps !
    Regards,
    Sowmya

  • [b][u]JSP/mySQL CREATE DATABASE problem[/u][/b]

    I am trying to create a mySQL DB through JSP program (query).
    The Query :
    stmt.executeUpdate("CREATE DATABASE employee;");
    is not working. PLEASE HELP ME.................
    The program is as follows.
    try
    Connection con =null;
    Class.forName("org.gjt.mm.mysql.Driver").newInstance();
    con=DriverManager.getConnection("jdbc:mysql://localhost:3306/bedrock","Dude","");
    System.out.println("Connection Established");
    try {
    System.out.println("Entered Try Block");
    stmt=con.createStatement();
    stmt.executeUpdate("CREATE DATABASE employee;");
    System.out.println("Query Executed");
    catch(Exception e){ 
    System.out.println("Entered Catch Block");
    System.out.println("Query Skipped");
    catch (SQLException ex)
    while (ex != null){
    System.out.println("sql exception"+ex);
    ex = ex.getNextException ();
    Message was edited by:
    sam_john

    con=DriverManager.getConnection("jdbc:mysql://localhost:3306/bedrock","Dude","");
    Access denied for user: '[email protected]' (Using password: NO)
    You must provide a password for your connection.
    Your code should have been as follows:
    con=DriverManager.getConnection("jdbc:mysql://localhost:3306/bedrock","Dude","YOUR_PASSWORD_HERE");Anyway, to create a database or a table in a db server like MySQL, you must have the good privileges to.
    Go to <MySQL_INSTALL_DIR>/Docs/ directory, you'll find there the MySQL manual.chm. Take a look at the the Tutorial section.
    In order to know how to use jdbc Connector/J, take a look at the documentation shipped with: /mysql-connector-java-X.X.X/docs/connector-j.html
    Here a typical code:
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.Statement;
    public class TestMySQL {
         public static void main(String[] args) {
              Connection con = null;
              Statement stmt = null;
              try {
                   Class.forName("org.gjt.mm.mysql.Driver").newInstance();
                   con = DriverManager.getConnection("jdbc:mysql://localhost:3306/bedrock", "Dude", "YOUR_PASSWORD_HERE");////// put the right password here
                   System.out.println("Connection Established");
                   System.out.println("Entered Try Block");
                   stmt = con.createStatement();
                   stmt.executeUpdate("CREATE DATABASE employee");
                   System.out.println("Query Executed");
              } catch (Exception e) {
                   e.printStackTrace();
              } finally {
                   if (stmt != null) {
                        try {
                             stmt.close();
                        } catch (Exception e) {
                   if (con != null) {
                        try {
                             con.close();
                        } catch (Exception e) {
    }Hope That Helps

  • Problem creating connection pool to mysql database

    Please, do not ignore this message and help me, if you have any Idea
    I have Sun Java System Application Server 8.1 installed on my computer, I installed also MySQL Connector/J to access MySql Databases through JDBC
    But now when I try to create new connection pool, an error comes:
    Following parameter were used:
    Name: MYSQL1
    Resource Type: javax.sql.XADataSource
    Database Vendor: mysql
    Datasource Classname: com.mysql.jdbc.Driver
    serverName 192.168.0.152
    port 3306
    networkProtocol
    user testuser
    password ***
    databaseName test
    datasourceName
    After saving and then klicking on Ping button, following error comes: "An error has occurred.
    Operation 'pingConnectionPool' failed in 'resources' Config Mbean. Target exception message: com.mysql.jdbc.Driver"
    I checked the logs of MySql, there was no attempt to access given Database or MYSQL-server at all
    What Am I doing wrong? How can I create MySql connection under Sun Java System Application Server 8.1?
    Any help will be appreciated

    The driver is in right place
    Originally I placed him in wrong directory and got an error, indicationg, that Driver class is not found, but then I corrected it, The problem is in connection to database - it doesn't work.
    I tired to load the same driver into Netbeans and could easyli create a connection to database, but I get it not working ander Sun Application server

Maybe you are looking for