graphic user interface. you can use java and create a simple connection with dat
ID: 3710954 • Letter: G
Question
graphic user interface. you can use java and create a simple connection with database to join the table my myqsl
all code posible with clear explanation and screenshot:
In this part of the project you are required to implement a Graphical User Interface for your database. Your interface must include a set of at least three different forms and a menu as follows:
Form 1:
The first form should display information from a single table in your database that you created in Step 2. The form should include at least four buttons (first, previous, next, and last). These buttons are supposed to allow the user to navigate through all the rows in the table. For example, the form shown below is used to display all rows in Customer table:
Form 2:
The second form should display information from more than one table. This means that the underlying query must include join between two or more table. The form layout can be same as for Form 1.
Form 3:
The third form should be divided into two parts. The first part reads input from the user. The form then uses the user input to retrieve information from the database and display the information in the other part of the form. For example, the below form takes Product Code as input. The form then retrieves and displays the corresponding vendor information.
Menu:
Implement a Menu to allow the user to use the three forms. For example, the below menu allows the user to use three forms to navigate through Customer, Product, or Vendor tables. When you click on any of the options, it should take you to Form 1.
| Database Form Customer Code First Name Last Name 10010 Alfred First Previous Next LastExplanation / Answer
Form 1 code:
//import required packages
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class RegistrationController extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String cc = request.getParameter("Customer Code");
String fname = request.getParameter("First Name");
String lname = request.getParameter("Last Name");
JButton registerButton=new JButton("First");
JButton resetButton=new JButton("Previous");
JButton nextButton=new JButton("Next");
JButton lastButton=new JButton("Last");
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
String query = "insert into student values(?,?,?)";
PreparedStatement ps = con.prepareStatement(query);
ps.setInt(1, cc);
ps.setString(2, fname);
ps.setString(3, lname);
ps.executeUpdate();
System.out.println("successfuly inserted");
ps.close();
con.close();
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
}
RequestDispatcher rd = request.getRequestDispatcher("home.jsp");
rd.forward(request, response);
}
}
Form 2 will display the databases in table format.
Form 3 code:- Here is the main logic of program. But be sure your database variable name and inserted query variable name must match.
try
{
Class.forName("com.mysql.jdbc.Driver");
java.sql.Connection con =DriverManager.getConnection("jdbc:mysql://localhost:3306/exam","riddhi","password");
java.sql.Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select stud.cc,stud_name,class from stud join account on stud.stud_id=account.stud_id;");//please give database variable name here.
while(rs.next())
{
int cc=rs.getInt(1);
String nm=rs.getString(2);
String clas=rs.getString(3);
model.addRow(new Object[]{id,nm,clas});
/* please give ur created database variable name.*/
}
}
catch(Exception e){}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.