Results 1 to 5 of 5
- 08-20-2010, 12:37 PM #1
Member
- Join Date
- Aug 2010
- Posts
- 28
- Rep Power
- 0
data is not inserting into database
Hello,
I am inserting data into the database using mysql and jsp. data is inserting as null into database not inserting values . can anyone tell me the solution for this? . am waiting ..
Here is the code:(.jsp)
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page language="java" import="java.sql.*;" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<center> <h3>Submit Your Resume</h3></center>
<form enctype="multipart/form-data" method="post" name="theform">
<table align="center" width="50%" border="0" cellspacing="5" cellpadding="0">
<tr>
<td>First Name:</td>
<td><input type="text" name="firstname"></td>
</tr>
<tr>
<td>Last Name: </td>
<td><input type="text" name="lastname" /></td>
</tr>
<tr>
<td>Mobile Number: </td>
<td><input type="text" name="mobilenumber" /></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" value="submit" name="submit" /></td>
</tr>
</table>
<%
String firstName=request.getParameter("firstname");
String lastName=request.getParameter("lastname");
String mobilenumber=request.getParameter("mobilenumber");
Connection con=null;
ResultSet rs=null;
Statement st=null;
try
{
String dbuser="root";
String dbpass="admin";
String url="jdbc:mysql://localhost/gb";
Class.forName("com.mysql.jdbc.Driver").newInstance ();
con=DriverManager.getConnection(url, dbuser, dbpass);
st=con.createStatement();
//String str="create table person(firstname varchar(40),lastname varchar(50),mobilenumber varchar(50))";
//st.execute(str);
String str2="insert into person values('"+firstName+"','"+lastName+"','"+mobilenum ber+"')";
st.executeUpdate(str2);
}
catch(Exception e)
{
System.out.println("Can not connect to database");
}
%>
</form>
</body>
</html>
Thanks in advance
Rashmi
- 08-20-2010, 02:07 PM #2
try this instead
and show us what it prints in the console since it will print out the exception that it is throwing.Java Code:catch(Exception e) { System.out.println(e); }
also did you notice the space in mobile number
you could also try this formatJava Code:String str2="insert into person values('"+firstName+"','"+lastName+"','"+mobilenum ber+"')";
Java Code:.executeUpdate("INSERT INTO myTable(test_id, " + "test_val) VALUES(2,'Two')");:rolleyes: ~ Sno ~ :rolleyes:
'-~ B.S. Computer Science ~-'
- 08-20-2010, 02:09 PM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Simply log the sql statement and check values are valid or not. Without debugging it's not possible to track it.
- 08-21-2010, 05:55 AM #4
Member
- Join Date
- Aug 2010
- Posts
- 28
- Rep Power
- 0
i tried ..it is not throwing any exceptions . database connection is executing but null value is inserting into the database.
- 08-21-2010, 03:05 PM #5
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
null values and inserting means that your program not evaluated the expected values. So you've to check that, check the logic that in data capturing.
Similar Threads
-
inserting date in oracle database
By jackjosh_in in forum Advanced JavaReplies: 6Last Post: 05-23-2010, 06:38 PM -
inserting values from jtable into database
By sandeepsai17 in forum New To JavaReplies: 1Last Post: 06-29-2009, 07:31 PM -
Inserting data to database from the form
By Ms.Ranjan in forum JavaServer Pages (JSP) and JSTLReplies: 2Last Post: 06-17-2008, 01:06 AM -
Inserting data containing quotes into DB
By Java Tip in forum Java TipReplies: 0Last Post: 02-06-2008, 09:28 AM -
Inserting file in to database
By Java Tip in forum Java TipReplies: 0Last Post: 01-07-2008, 08:39 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks