• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

while inserting into database

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
}
_________________________________________________________________

------------------
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sometimes I wonder whether people just post to get their quotum for the giveaway... I may be wrong though...
- Peter
 
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Funny is how many people post JDBC questions in the JSP/Servlet forum.
 
Arun Jassiar
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks guy it worked
Bye
Arun
 
To avoid criticism do nothing, say nothing, be nothing. -Elbert Hubbard. Please critique this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic