This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes JDBC and the fly likes Getting null values in table even after the input Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Getting null values in table even after the input" Watch "Getting null values in table even after the input" New topic
Author

Getting null values in table even after the input

rajashree loganayagi
Greenhorn

Joined: Apr 12, 2011
Posts: 20
Hi,

I tried to insert a data into MS Access Database using jsp. For that i created a HTML program which as the same field as in the dB table.

After i input all the fields using HTML, i found that some of the fields in the table are stored as null.

Please a provide a solution to avoid the null values even i input the field.

Thanks in advance....
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

You'll need to tell us more about how you do what you are doing for us to be able to help. Can you post your code?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
rajashree loganayagi
Greenhorn

Joined: Apr 12, 2011
Posts: 20
These are the following codes i used to insert the data:



</head>
<body>
<%
String project = request.getParameter("project");
String odr = request.getParameter("odr");
String resource = request.getParameter("resource");
String review = request.getParameter("review");
String status = request.getParameter("status");
String reviewcycle = request.getParameter("review_cycle");
String designowner = request.getParameter("design_owner");
String ctiriss= request.getParameter("ctir_iss");
String highiss= request.getParameter("high_iss");
String mediss = request.getParameter("med_iss ");
String score = request.getParameter("score");
String receivedon = request.getParameter("received_on");
String startdate = request.getParameter("start_date ");
String enddate = request.getParameter("end_date");
String remarks = request.getParameter("remarks ");

Connection conn = null;
Statement stmt = null;
ResultSet rs = null;

try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn=DriverManager.getConnection("Jdbc:Odbc:ShreeDB");
stmt = conn.createStatement();

try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn=DriverManager.getConnection("Jdbc:Odbc:ShreeDB");
stmt = conn.createStatement();

stmt.executeUpdate("Insert into ProjTable (Project,ODR,Resource,Review,Status,Review_Cycle,Design_Owner,Crit_Iss,High_Iss,Med_Iss,Score,Received_On,Start_Date,End_Date,Remarks) values ('"+project+"','"+odr+"','"+resource+"','"+review+"','"+status+"','"+reviewcycle+"','"+designowner+"','"+ctiriss+"','"+highiss+"','"+mediss+"','"+score+"','"+receivedon+"','"+startdate+"','"+enddate+"','"+remarks+"')");
out.println("Data inserted successfully");
}
catch(Exception e)
{
out.println(e.toString());
}

%>

</body>
</html>


I got the null value for 4 fields: ctiriss,mediss,startdate and remarks.....

And rest of the fields are works fine.....
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Have you checked the values you have from your request.getParameter() calls? The obvious cause is nothing is included in the request for these.
Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 820

Paul is right.

print out your sql and you will probably see some missing values:
or, post the HTML here and you will spot some wrong names in the HTML form
rajashree loganayagi
Greenhorn

Joined: Apr 12, 2011
Posts: 20
I even tired using out.println() .... It shows "null".

Here are the HTML codes:



Thanks for the valuable suggestions......
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1473
    
    6



Look at the name and argument in getParameter. crit_iss and ctir_iss.


Swastik
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19674
    
  18

rajashree loganayagi wrote:

Your application is highly susceptible to SQL injection. I suggest you start using PreparedStatement instead of Statement.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 820

so, which fields are ending up null?
rajashree loganayagi
Greenhorn

Joined: Apr 12, 2011
Posts: 20
After rectifying the spell of critiss, i can able to get the values....

But still 3 fields(mediss,startdate,remarks)states only null....
Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 820

But still 3 fields(mediss,startdate,remarks)states only null....

well, those three have an extra space at the end of the string when you call getParameter:



rajashree loganayagi
Greenhorn

Joined: Apr 12, 2011
Posts: 20
Thank you so much.... Now i can able to get the values exactly....
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Getting null values in table even after the input