0

I am trying to insert some data in a data base. But something goes wrong, but first let me tell what goes right:

My ms access dsn is working well without jsp, I am able to insert data using a simple java program.

Apache is running as half of the code and other files are working. I don't get any error messages ...and its not even printing the try catch message.

Here is the code:

    <html>
    <body>
    <%@ page import="java.sql.*"%>
    <%
    String name=request.getParameter("name");
    int rno=Integer.parseInt(request.getParameter("rollno"));
    int marks=Integer.parseInt(request.getParameter("marks"));


    out.println(name+"\n");
    out.println(rno+"\n");
    out.println(marks+"\n");
  //till here it works fine and print data 
    try{
    out.println("this too gettiing right");
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    out.println("even this line is also getting printed");

    Connection con=DriverManager.getConnection("jdbc:odbc:mydsn");
    out.println("But NOt this line"); 

    PreparedStatement ps=con.prepareStatement("insert in student values(?,?,?)");
    out.println("afte connection");
    ps.setInt(1,rno);
    ps.setString(2,name);
    ps.setInt(3,marks);
    int i=ps.executeUpdate();
    if(i>0){out.println("inserted ");}
    else{out.println("not inserted");}
    ps.close();
    con.close();


    }
    catch(SQLException se)
   {
   System.out.println(se);
   }
   catch(ClassNotFoundException e)
   {
   System.out.println(e);
   }

  %>
 </body>
 </html>

please help me find out what is wrong here

superuser0
  • 127
  • 1
  • 1
  • 12
Anuja
  • 33
  • 6
  • can you post the exception you are getting ? – Velu Jul 12 '13 at 08:51
  • i am not getting any exception message.this code generates this output "anuj 89 2323 this too gettiing right even this line is also getting printed" only – Anuja Jul 12 '13 at 10:59

1 Answers1

0

You need to make couple of changes to the jsp code.

String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=myDB.mdb;";
Connection conn = DriverManager.getConnection(database, "username", "password");

Also have a look at this

Community
  • 1
  • 1
Velu
  • 1,681
  • 1
  • 22
  • 26
  • I made these changes but i am still getting same thing ..that is no error and no execution after connection and what do u want me to note in link u gave ..(do u mean modularity ? or anything else?) – Anuja Jul 12 '13 at 10:57
  • i tried same code in netbeans and its working ....then why its not working with appache using notepad ? – Anuja Jul 12 '13 at 19:48