Problem in inserting data into MySQL from JSP!!!
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Abhishek_Bhattacharya
Posted On:   Sunday, November 25, 2007 12:42 PM

Hi, I am using a JSP form 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 <%@ page import="java.sql.*" %> <%@ page import="java.io.*" %> <% try { Class.forName("com.mysql.jdbc.Driver").newInstance(); Connection conn = DriverManager.getConnection("jdbc:mysql://url.com:3306/DB", "gues   More>>

Hi,

I am using a JSP form 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











<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>
<%
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:mysql://url.com:3306/DB", "guest", "1234567");
%>


<%
String action = request.getParameter("action");
if(action != null && action.equals("insert")) {
conn.setAutoCommit(false);
PreparedStatement pstmt = conn.prepareStatement(("INSERT INTO Table VALUES(?, ?, ?, ?, ?, ?, ?)"));
pstmt.clearParameters();
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"));
pstmt.executeUpdate();
conn.commit();
conn.setAutoCommit(true);
}
%>

<%
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM Table");
%>




























<%
while(rs.next()) {
%>













<%
}
%>


Col1 Col2 Col3 Col4 Col5 Col6 Col7
<%= rs.getInt("col1") %> <%= rs.getString("col2") %> <%= rs.getInt("col3") %> <%= rs.getString("col4") %> <%= rs.getString("col5") %> <%= rs.getString("col6") %> <%= rs.getString("col7") %>


<%
rs.close();
stmt.close();
conn.close();
} catch (SQLException sqle) {
out.println(sqle.getMessage());
} catch (Exception e) {
out.println(e.getMessage());
}
%>



Thank You!!!    <<Less

Re: Problem in inserting data into MySQL from JSP!!!

Posted By:   Robert_Lybarger  
Posted On:   Sunday, November 25, 2007 08:06 PM

Your first problem is that your question is unintelligible -- maybe next time you should preview and edit the post to make sure it is readable and properly formatted before blindly just posting it. So since I'm not going to bother looking through any of that mess of code you dumped in, do you have any logging set up? Have you checked Tomcat's usual log files? Are you getting any exceptions thrown that you are ignoring?
About | Sitemap | Contact