hi everyone, i am new to netbeans. i am creating a system that can allocate rooms to students. My main problem is how to find out which rooms are full and which ones are available.
I am using Mysql and Java Netbeans. I have read some of the tutorials but i haven't fond out how i can do it.
does anyone know how i can do this in netbeans. Please help

Recommended Answers

All 4 Replies

i cant give you the code but i can tell you how to retrive data from database.
you can take help from the following example.

1.the user enter the table name on the web page the coding is given below

<html>
  <head>
    <title></title>
  </head>
  <body bgcolor="green">
   <center>
  <form  name="f1" action="http://localhost:8084/Database/TestJdbc" method="Post">
      Enter the table name : <input type="text" name="t1"  /><br>
       <input type="submit" value="OK" />
       </form>
       </center>
       </body>
</html>

2.the server side coding is given below

/*
 * TestJdbc.java
 *
 * Created on August 30, 2009, 8:26 PM
 */

import java.io.*;
import java.net.*;
import java.sql.*;

import javax.servlet.*;
import javax.servlet.http.*;

/**
 *
 * @author G@Me BuDDiE
 * @version
 */
public class TestJdbc extends HttpServlet {
    
    /** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        /* TODO output your page here*/
        out.println("<html>");
        out.println("<head>");
        out.println("<title>Servlet TestJdbc</title>");
        out.println("</head>");
        out.println("<body>");
        
        out.println("<h1>Servlet TestJdbc at " + request.getContextPath () + "</h1>");
          try{
             Connection conn;
             Statement stmt;
             Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
             conn=DriverManager.getConnection("Jdbc:Odbc:SelectData");
             stmt=conn.createStatement();
             String s = request.getParameter("t1");
             ResultSet rs=stmt.executeQuery("select * from  " +s);
             out.println("<table border = 1>");
             while(rs.next())
             {
                 out.println("<tr><td>");
                 out.println(rs.getString(1)+"</td>");
                out.print("<td>");
                 out.println(rs.getString(2)+"</tr></td>");                 
             }
             out.println("</table>");
             
         }catch(Exception e){}
        out.println("</body>");
        out.println("</html>");
     
        out.close();
    }
    
    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }
    
    /** Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }
    
    /** Returns a short description of the servlet.
     */
    public String getServletInfo() {
        return "Short description";
    }
    // </editor-fold>
}

you have to create a database and store the database where your java file is stored which will be easier during coding.any more help you can ask.

commented: By giving out solution you are not helping to the learning process, you just helping lazy students to pass their assignments and fail in real life -2

That is not a good example and it is a bad way to do things. Not to mention that the OP said nothing about html code.

Only the database connectivity is almost ok. You forgot to close the ResultSet, Statement and ResultSet.
First: How do you know that the table entered at the field will always have 2 columns.
Second: Never put html code in servlets. Read the data from the DB, put those into an array of objects using OOP, and then send the array of objects back to a jsp through the request in order to be displayed at the jsp page.

Of course the above would have been helpful if the OP has said that the whole application would be web application.

commented: good +0

Of course, first you have to create the database and store it in the your Java file. You can develop MySQL backed applications with Netbaens and JAVA which might could give you the other Web services. It would be easier for you if you create the proper database so that you can allocate rooms to the students.

                I want a code in which a jsp login page is calling a servlet and the server is connected to the again new jsp in which it shows the welcome page or it says that you are a valid user or it may be invalid user....plz ans as soon as possible, 
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.