my dog learned polymorphism*
The moose likes Servlets and the fly likes while inserting into database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "while inserting into database" Watch "while inserting into database" New topic
Author

while inserting into database

Arun Jassiar
Greenhorn

Joined: Mar 16, 2001
Posts: 4
I am getting folloing error while inserting into a access database.
---------------------------------------------------------------
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:4246)
at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(JdbcOdbc.java:1172)
at sun.jdbc.odbc.JdbcOdbcStatement.execute(JdbcOdbcStatement.java:206)
at sun.jdbc.odbc.JdbcOdbcStatement.executeUpdate(JdbcOdbcStatement.java:
163)
at InsertArticle.doPost(InsertArticle.java, Compiled Code)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:4
04)
at org.apache.tomcat.core.Handler.service(Handler.java:286)
at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372
)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.
java:797)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:743
)
at org.apache.tomcat.service.http.HttpConnectionHandler.processConnectio
n(HttpConnectionHandler.java:210)
at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java,
Compiled Code)
at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java
, Compiled Code)
at java.lang.Thread.run(Thread.java:479)
----------------------------------------------------------------

Help me to do it.
My Code is below.
thanks.
Arun
__________________________________________________________
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.sql.*;
import java.util.Date;
public class InsertArticle extends HttpServlet{
// Data base connection
Connection dbCon;
// establish a connection and share it across all request
public void init(ServletConfig config) throws ServletException
{
super.init(config);
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
dbCon=DriverManager.getConnection("jdbc dbc:CDGArticle");
}
catch (ClassNotFoundException e)
{
System.out.println("JDBC - ODBC Bridge not found");
return;
//catch1 closed
}
catch (SQLException e)
{
System.out.println("SQL exception thrown init");
return;
// catch2 closed
}
//init closed
}
// caaling doGet to process GET request
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException
{
try
{
String authorName=request.getParameter("authorName");
String subject=request.getParameter("subject");
String message=request.getParameter("message");
//int i=0;
response.setContentType("text/html");//retuns html
//handle output Stream
PrintWriter out=response.getWriter();
String query = "select authorName, subject, message from CDGKnowledgeHub ";
String query1="insert into CDGKnowledgeHub"+ "values ( 'authorName' + ' subject' +'message')";

Statement stat=dbCon.createStatement();
//int visitor1=
stat.executeUpdate(query1);
ResultSet visitor=stat.executeQuery(query1);
while (visitor.next()) {
String a = visitor.getString(authorName);
String s = visitor.getString(subject);
String m = visitor.getString(message);
System.out.println(a+"\n"+ s+ "\n" + " " + m);
}

stat.close();
dbCon.close();

/*if (visitor1!= 0)
{
dbCon.commit();
//int intMsg = m.sendMessage();
out.println("Thanks "+authorName+". Your change request has been sent to Corporate Intranet Group.");
}//if closed
else
{
dbCon.rollback();
out.println("Kindly try again, the transaction could not be executed");
out.println("<a href=javascript:history.back(); > Back </a> ");
} // else closed*/
}
catch (Exception e)
{e.printStackTrace();
}
//doGet Closed
}
public String getServletInfo()
{
return "CDGArticle servlet";
}
//DisplayArticle closed
}
_________________________________________________________________

------------------
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Originally posted by Arun Jassiar:
I am getting folloing error while inserting into a access database.

Try inserting a space between your table name and the "values" keyword. (Funny how staring at code for too long can blind you).
- Peter
Shibin Raghavan
Greenhorn

Joined: Mar 29, 2001
Posts: 11
Originally posted by Arun Jassiar:
I am getting folloing error while inserting into a access database.

The problem is with the string 'query1'.
The correct one should be like the one given below:
String query1 = "insert into CDGKnowledgeHub values('" + authorName + "','" + subject + "','" + message + "')";
Then again compile and run it.........
Bye.
Regards,
Shibin
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Sometimes I wonder whether people just post to get their quotum for the giveaway... I may be wrong though...
- Peter
Andrew Shafer
Ranch Hand

Joined: Jan 19, 2001
Posts: 338

Funny is how many people post JDBC questions in the JSP/Servlet forum.


!_I_Know_Kung_Fu_!
Arun Jassiar
Greenhorn

Joined: Mar 16, 2001
Posts: 4
Thanks guy it worked
Bye
Arun
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: while inserting into database
 
Similar Threads
Running a simple java program
procedure to establish database connectivity
result set not retrieved
Please Help:Access to Sql Server from servlet
HTTP method POST is not supported by this URL