Results 1 to 4 of 4
  1. #1
    nishant.4545 is offline Member
    Join Date
    Jul 2009
    Posts
    10
    Rep Power
    0

    Default problem with jdbc in jsp

    I have created a simple form using html as
    Java Code:
    <html>
    <center>
    <b>
    Enter the data
    </b>
    
    <form action="Insert.jsp" method="get">
    
    Name:  <input type="text" name="firstName">
        <input type="text" name="lastName"><br>
    Sex:
        <input type="radio" checked name="sex" value="male">Male
        <input type="radio" name="sex" value="female">Female
    <br>
    <input type="submit">
    </center>
    </html>

    Then I want to store this data in a database for which I have created a jsp as

    Java Code:
    <html>
    <head>
    <title>inserting to table</title>
    </head>
    <body>
    <%@ page language="java" import="java.sql.*" %>
    <%String firstName = request.getParameter("firstName");
        String lastName = request.getParameter("lastName");
        String sex = request.getParameter("sex");
        
       try{
    		       	   
     	    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
       		
       	String database = 
                  "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=Data.mdb;";
                  Connection conect= DriverManager.getConnection(database, "","");
       		
       		Statement stm=conect.createStatement();
       		
       		stm.execute("insert into Cinfo values('"+firstName+"','"+lastName+"','"+sex+"')");
            stm.close();
            conect.close();   		
       	
       	
       		
     	   }	catch(ClassNotFoundException cnf){
    		out.println("Class not found error"+cnf);
    		}catch(SQLException sqe){
       		out.println("SQL ERROR 2:"+sqe);
       		
       	    }
    
    
    %>
    </body>
    </html>
    I use tomcat to run jsp files. I have placed all the three files- Info.html, Insert.jsp and Data.mdb(database) in the folder-
    C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\ROOT
    I access the html file from my browser by directing it to:
    localhost:8080/Info.html


    The html file is displayed perfectly well. But when I try to insert data in database by clicking on "submit" button, I get the following exception-

    SQL ERROR 2:java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Could not find file '(unknown)'.

    I guess it is because it is unable to find the database. But my database is there in the same folder.

    Please help me.
    Thanx in advance.

  2. #2
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    877
    Rep Power
    8

    Default

    Hi,
    Ur database connectivity information is wrong. Have u created the dsn name?.

    Say if u create ur dsn for example as

    "Test" then

    u need to give like this below
    Connection conect = DriverManager.getConnection("jdbc:odbc:Test");
    Ramya:cool:

  3. #3
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    10

    Default

    Then you also need to put all that database connection code in separate pure Java class. You should use JSPs for presentation only.

  4. #4
    serjant's Avatar
    serjant is offline Senior Member
    Join Date
    Jun 2008
    Location
    Ukraine,Zaporozhye
    Posts
    487
    Rep Power
    9

    Default

    To make connection use these lines:

    Java Code:
    // Load the database driver
          Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" ) ;
    
          // Get a connection to the database Data.mdb
          Connection conn = DriverManager.getConnection( "jdbc:odbc:Data" ) ;

Similar Threads

  1. Problem in JDBC
    By Preethi in forum New To Java
    Replies: 11
    Last Post: 01-08-2009, 06:18 PM
  2. Jdbc problem
    By abhiN in forum JDBC
    Replies: 1
    Last Post: 03-21-2008, 06:10 AM
  3. JDBC select problem
    By abhiN in forum JDBC
    Replies: 0
    Last Post: 03-12-2008, 09:09 AM
  4. JDBC problem
    By Swamipsn in forum New To Java
    Replies: 1
    Last Post: 08-13-2007, 06:05 PM
  5. JDBC problem
    By peiceonly in forum Threads and Synchronization
    Replies: 2
    Last Post: 08-03-2007, 01:42 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •