• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

insertion into the database

 
gaurav chhabra
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sir
the code below is to enter the items in the database but it is giving the error .......of null.................

<!-- JAI SHRI RAM -->
<%@ page import="java.sql.*" %>
<html>
<head><title>JAI SHRI RAM</title></head>
<body>

<%

String url = "jdbc dbc:lala" ;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection(url,"","");
Statement st = conn.createStatement();
for(int i=1 ; i<=13 ; i++)
{
String skill_type = request.getParameter("skill_type"+i);
String skill_name = request.getParameter("skill_name"+i);
String version = request.getParameter("version"+i);
String lastused = request.getParameter("last_used"+i);
int last_used = Integer.parseInt(lastused);
String proficiency_level = request.getParameter("proficiency_level"+i);
String expinyears = request.getParameter("exp_in_years"+i);
int exp_in_years = Integer.parseInt(expinyears);
String expinmonths = request.getParameter("exp_in_months"+i);
int exp_in_months = Integer.parseInt(expinmonths);


String query = "insert into skills values(1 , '" + skill_type + "' , '" + skill_name + "', '" + version + "', 1 , '" + proficiency_level + "', 1 ,1)";
st.executeUpdate(query);
}
out.println("JAI SHRI RAM ,,,,,,,, transcation is over");

%>

</body>
</html>

i m using MS ACCESS
please tell me the problem

thank you
gaurav
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it is giving the error .......of null.................

What is giving the error?

Are you seeing a stack trace in your browser?
If so, is there a "ROOT CAUSE" section?
If not, what's in your server's logs?

There are several things in this code that could cause a NullPointerException (NPE).

Start by putting an "out.println" statement under each call to getParameter to see if you are getting the values that you are expecting from the form.


If not, you will see a NullPointerException when you try to convert the value to an int.

Also, print the value of your SQL query to the page.
Do you already know that you are successfully connecting to the database?

There are a lot of debugging steps that you should go through before asking for help. If you start by posting to a forum, you are selling yourself short.

If you do finally give up and want to look to a forum for help, make it as easy as possible for people to help you. Use the UBB Code tag to wrap the code that you post so your indenting will be preserved. This makes it much easier to us to read it. Post the actual error message instead of typing
"it is giving the error .......of null". Also, state the steps you have gone through so we don't spend time doing the same thing. IE: let us know if you've already connected to the database with the same DSN, etc..
[ February 26, 2005: Message edited by: Ben Souther ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What Ben said... and, moved to the JDBC forum since this really has nothing to do with JSP.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic