1. Присоединяйся! Электронный журнал "BMW Club Magazine" в Telegram
    Скрыть объявление
  2. BMWClub Страхование
    Лучшие условия при покупке полиса для участников клуба!
    Скрыть объявление

Insert Data from DB (**********)

Тема в разделе "Образование", создана пользователем Night Stranger, 2 дек 2009.

  1. Night Stranger

    Night Stranger Завсегдатай

    Регистрация:
    15 авг 2007
    Сообщения:
    1,533
    Пол:
    Мужской
    Регион:
    Москва
    Водит:
    Zdravstvujte. Sro4no nujno reshit vopros.
    Est' Code kotorij po zaprosu vidaet informaciju iz bazi dannih:

    <%@ page language="****" contentType="text/html"%>
    <%@ page import="****.sql.*" %>
    <% String strTitle="Search Result"; %>


    <%! String dblocation, dbdate, entry_body, entry_name, boatquerry; %>
    <% dblocation = request.getParameter("location"); %>
    <% dbdate = request.getParameter("date"); %>


    <html>
    <head>
    <title><%= strTitle %></title>
    <%! String myUserName = "group15"; %>
    <!-- stylesheet link here -->
    </head>
    <body>
    <h1><%= strTitle %></h1>
    <%
    String strHost = "localhost";
    String strDBName = myUserName;
    String strConnectURL = ("jdbc:postgresql://" + strHost + "/" + strDBName);
    String strUser = myUserName;
    String strPassword = myUserName; // same as username unless you have changed it!
    // implicitly load the driver - static code in Driver registers itself with the
    // JDBC driver manager
    Class.forName("org.postgresql.Driver");
    ResultSet rs = null;
    ResultSet ss = null;
    Connection con = null;
    Statement s = null;
    int nRowCount = 0;
    try
    {
    // CONNECT TO THE DATABASE
    con = DriverManager.getConnection(strConnectURL, strUser, strPassword);
    s = con.createStatement();
    // EXECUTE SQL QUERIES HERE
    //String insertSQL = " insert into message (subject, body, author) values " + "('"+entry_subject+ "','"+ entry_body+"','"+ entry_name +" ')";
    //int result = s.executeUpdate(insertSQL);

    if((!dblocation.equals("0"))&&(dbdate.equals("0")))
    {// DISPLAY ALL THE MESSAGES
    String strSQL = "SELECT boat.name, provider, cabins, beds, price FROM boat,provider WHERE boat.provider=provider.name AND provider='"+dblocation+"'";
    rs = s.executeQuery(strSQL);
    //rs.afterLast();
    String[][] boatarray=new String[5][50];
    //String provider[], cabins[], beds[],price[];
    int i=0,j=0;
    while(rs.next())
    {
    boatarray[j]=rs.getString("name");
    i++;
    boatarray[j]=rs.getString("provider");
    i++;
    boatarray[j]=rs.getString("cabins");
    i++;
    boatarray[j]= rs.getString("beds");
    i++;
    boatarray[j]=rs.getString("price");
    i=0;
    j++;



    }
    for(int l=0;i<j;i++)
    {
    int k=0;
    strSQL = "SELECT date,cost,temp1.price FROM (SELECT pricelist.price,cost,date FROM pricelist,boat WHERE pricelist.price=boat.price AND name='"+boatarray[k][l]+"') temp1 WHERE NOT EXISTS(SELECT startdate, (noofweeks*7+startdate-1) FROM booking WHERE boatname='"+boatarray[k][l]+"' AND temp1.date>=startdate AND temp1.date<=(noofweeks*7+startdate-1));";

    out.println( "<br>" + boatarray[k++][l] + "<br>provider " + boatarray[k++][l] + "<br>cabin " + boatarray[k++][l] + "<br>beds "+ boatarray[k++][l]+"<br>price: "+boatarray[k++][l]+"<br>");
    ss = s.executeQuery(strSQL);
    out.println("<table><tr>");
    int m=0;
    while(ss.next())
    {

    out.println("<td>"+ss.getString("date")+"</td><td>cost</td><td>"+ss.getString("cost")+"</td>");
    m++;
    if((m%6)==0)
    {
    out.println("</tr><tr>");
    }

    }
    out.println("</tr></table>");
    l++;
    }
    }

    if((dblocation.equals("0"))&&(!dbdate.equals("0")))
    {// DISPLAY ALL THE MESSAGES
    String strSQL = "SELECT boat.name, provider, cabins, beds, price FROM boat WHERE NOT EXISTS (SELECT boatname, (noofweeks*7+startdate-1) FROM booking WHERE startdate<='"+dbdate+"' AND (noofweeks*7+startdate-1)>='"+dbdate+"' AND boatname = boat.name) ORDER BY boat.name";
    rs = s.executeQuery(strSQL);
    //rs.afterLast();
    while(rs.next())
    {
    out.println( "<br>" + rs.getString("name") + "<br>provider " + rs.getString("provider") + "<br>cabin " + rs.getString("cabins") + "<br>beds "+ rs.getString("beds")+"<br>price: "+rs.getString("price")+"<br>"); }
    }
    if((!dblocation.equals("0"))&&(!dbdate.equals("0")))
    {
    // DISPLAY ALL THE MESSAGES
    String strSQL = "SELECT * FROM (SELECT boat.name,provider,cabins, beds,price FROM boat WHERE NOT EXISTS (SELECT boatname, (noofweeks*7+startdate-1) FROM booking WHERE startdate<='"+dbdate+"' AND (noofweeks*7+startdate-1)>='"+dbdate+"' AND boatname = boat.name) ORDER BY boat.name)AS temp2 WHERE temp2.provider='"+dblocation+"'";
    rs = s.executeQuery(strSQL);
    //rs.afterLast();
    while(rs.next())
    {
    out.println( "<br>" + rs.getString("name") + "<br>provider " + rs.getString("provider") + "<br>cabin " + rs.getString("cabins") + "<br>beds "+ rs.getString("beds")+"<br>price: "+rs.getString("price")+"<br>"); }



    }

    }
    // Boilerplate exception handling.
    catch( SQLException e )
    {
    String strSQLError = "";
    // print details of SQL errors - there could be multiple errors chained together
    while ( e != null)
    {
    strSQLError += ("SQLException : " + e.getMessage() + " " );
    strSQLError += ("SQLState : " + e.getSQLState() + " " );
    strSQLError += ("SQLCode : " + e.getErrorCode() + " ");
    e = e.getNextException();
    }
    out.println("<div style='color:red;'>" + strSQLError + "</div>");
    }
    catch ( Exception e)
    {
    // some other exception
    out.println(e);
    }
    finally
    {
    try
    {
    if (rs != null)
    rs.close();
    if (s != null)
    s.close();
    if (con != null)
    con.close();
    }
    catch (Exception e)
    {
    out.println(e);
    }
    }
    %>

    </body>
    </html>

    Jirnim shriftom videlenno mesto kotoroe nujno otobrajat v tablice po kategorijam. Kak eto v ********** ili JSP sdelat?

    Spasibo
     
  2. Night Stranger

    Night Stranger Завсегдатай

    Регистрация:
    15 авг 2007
    Сообщения:
    1,533
    Пол:
    Мужской
    Регион:
    Москва
    Водит:
    po4emu-to slovo **** Script on pos4ital maternim v nazvanii temi
     

Яндекс.Метрика