I am using a JSP from to collect data from user and then inserting those values into a table in MySQL.But it is returning 'null' always.I am able to query the DB and view the entire table and everything else is fine. But the INSERT is not working somehow!!!
Please help me in solving my problem!!!
The code is as follows:

DBMS Project
<body bgcolor=#FFFFFF>
<font color=black>
<img src="logo.JPG" width="280" height="120"/>
       <%@ page import="java.sql.*" %>
       <%@ page import="java.io.*" %>
	    try {
		   Connection conn = DriverManager.getConnection("jdbc:mysql://url.com:3306/DB", "guest", "1234567");
	    String action = request.getParameter("action");
	    if(action != null && action.equals("insert"))  {
	    PreparedStatement pstmt = conn.prepareStatement(("INSERT INTO Table VALUES(?, ?, ?, ?, ?, ?, ?)"));
	    pstmt.setInt(1, Integer.parseInt(request.getParameter("Col1")));
	    pstmt.setString(2, request.getParameter("Col2"));
	    pstmt.setInt(3, Integer.parseInt(request.getParameter("Col3")));
	    pstmt.setString(4, request.getParameter("Col4"));
	    pstmt.setString(5, request.getParameter("Col5"));
	    pstmt.setString(6, request.getParameter("Col6"));
	    pstmt.setString(7, request.getParameter("Col7"));
	    Statement stmt = conn.createStatement();
	    ResultSet rs = stmt.executeQuery("SELECT * FROM Table");
<table border="1" cellspacing="6" > 
	    <form action="Page.jsp" method="get">
	    <input type="hidden" value="insert" name="action">
	    <th><input value="" name="Col1" size="9"></th>
	    <th><input value="" name="Col2" size="10"></th>
	    <th><input value="" name="Col3" size="15"></th>
	    <th><input value="" name="Col4" size="15"></th>
	    <th><input value="" name="Col5" size="10"></th>
	    <th><input value="" name="Col6" size="10"></th>
	    <th><input value="" name="Col7" size="10"></th>
	    <th><input type="submit" value="Insert"></th>
	    while(rs.next()) {
	<td> <%= rs.getInt("col1") %></td>
	<td> <%= rs.getString("col2") %></td>
	<td> <%= rs.getInt("col3") %></td>
	<td> <%= rs.getString("col4") %></td>
	<td> <%= rs.getString("col5") %></td>
        <td> <%= rs.getString("col6") %></td>
        <td> <%= rs.getString("col7") %></td>
	}  catch (SQLException sqle) {
	}  catch (Exception e) {

Thank You!!!

Few thinks to this
1) JSP should not be use any more to communicate with DB, you need to use servlets
2) Do not use GET method for action POST is better
3) You have no validation on your data, which is very bad (don't expect user to always provide correct data, even if this is school work. Teachers like to check on this sort of mistakes)
Check Sun website and these tutorials on how to do it

Please follow the suggestions outlined by peter_budo.

Also, your best perhaps to avoid embedding scriplet code and use tag notation. See JSTL for example.

You might be new to this area, try and follow best practices and it will make life far easier.

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.