Results 1 to 4 of 4
Thread: problem with jdbc in jsp
- 08-17-2009, 08:45 AM #1
Member
- Join Date
- Jul 2009
- Posts
- 10
- Rep Power
- 0
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>
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.
- 08-17-2009, 10:40 AM #2
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:
- 08-24-2009, 11:15 AM #3
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 11
Then you also need to put all that database connection code in separate pure Java class. You should use JSPs for presentation only.
- 08-29-2009, 01:31 PM #4
Similar Threads
-
Problem in JDBC
By Preethi in forum New To JavaReplies: 11Last Post: 01-08-2009, 05:18 PM -
Jdbc problem
By abhiN in forum JDBCReplies: 1Last Post: 03-21-2008, 05:10 AM -
JDBC select problem
By abhiN in forum JDBCReplies: 0Last Post: 03-12-2008, 08:09 AM -
JDBC problem
By Swamipsn in forum New To JavaReplies: 1Last Post: 08-13-2007, 06:05 PM -
JDBC problem
By peiceonly in forum Threads and SynchronizationReplies: 2Last Post: 08-03-2007, 01:42 PM
Bookmarks