• 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

can anybody help me

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Iam trying to view the changes that i made in my html by using servlet,as
import javax.swing.*;
import java.util.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class postparametersservlet extends HttpServlet
{
private Connection connection;
private JTable table;
String url="jdbc dbc:book";
public void doPost(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException
{
String isbn[]={"1234","34234","45362","78960"};
String name[]={"java","c++","c","oracle"};
String data=request.getParameter("data");
Cookie c=new Cookie("java","isbn");
response.setContentType("text/html");
PrintWriter pw=response.getWriter();
response.addCookie(c);
pw.println("<html><head><title>");
pw.println("cod cookies");
pw.println("</title></head><body>");
pw.println(data);
if(data=="java")
{
pw.println(isbn[2]);
}
pw.println("</body></html>");
pw.close();
}
}
and my html is,
<html>
<body>
<center>
<form name="Form1" method="get" action="http://localhost:8080/servlet/postparametersservlet">
select the Name of the book<select name="data">
<option value="java" selected>java
<option value="c++">C++
<option value="c">C
<option value="oracle">oracle
</select><br><br>
<input TYPE="SUBMIT" ></body>
</html>
Like if i select the book "java" it has to display the isbn number of the book.
Is there anything wrong in that?
please help me.
rajani
 
Ranch Hand
Posts: 977
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Instead of using if(data=="java")
try it using if(data.equals("java"))
and please let me know if it works
[This message has been edited by Marcos Maia (edited July 18, 2001).]
 
rajani adapa
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank u.
it's working.but,i've another question.
I want to create a database that stores information about customer choices.Like,my html page contains a choice of text books.Corresponding to the selection the user made, i want to insert the isbn number of the book in the database.
If i try to do that iam getting an error message saying that"no db".
please check this out.
import java.io.*;
import javax.swing.*;
import java.util.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class postparametersservlet extends HttpServlet
{
private Connection connection;
private JTable table;
String url="jdbc dbc:book";
public void doPost(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException
{
String isbn[]={"1234","34234","45362","78960"};
String name[]={"java","c++","c","oracle"};
String data=request.getParameter("data");
Cookie c=new Cookie("java","isbn");
response.setContentType("text/html");
PrintWriter pw=response.getWriter();
response.addCookie(c);
pw.println("<html><head><title>");
pw.println("cod cookies");
pw.println("</title></head><body>");
pw.println(data);
pw.println("</body></html>");
pw.close();
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
connection=DriverManager.getConnection(url);
}
catch(ClassNotFoundException cnf)
{
System.out.println("no class");
}
catch(SQLException sqle)
{
System.out.println("no db");
}
try
{
Statement s=connection.createStatement();
String q;
if(data.equals("java"))
{
q="insert into choices(bookname, isbnnumber)values(data,isbn[0])";
connection.nativeSQL(q);
int result=s.executeUpdate(q);
if(result==1)
System.out.println("successfull");
else
System.out.println("unsuccessfull");
s.close();
}
}
catch(SQLException sqle)
{
System.out.println("failed access");
}
}
}
 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I haven't perused your code with too much attention, but make sure you register your DB in the ODBC Administrator in Control Panel ( on Win 9x machines ). If that isn't the problem, I would go ahead and blame the Jdbc-Odbc bridge. It's not so hot, as I found out myself. Try using a 3rd party driver ( I used the one at www.infozoom.de ). Good luck.
Kevin
 
rajani adapa
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes,
i did register my database in odbc administrator in control panel.
what should i do now?
thanks in advance
rajini
 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I personally don't use the JDBC-ODBC drivers (a slight overhead) but instead just use type IV drivers (i.e - mm.mysql)
I'm not sure but should there be a username/password associated with accessing the database? Because I didn't see this in your implementation. Maybe it's just the databases that I use which require this in the connection and not the one that you use.
 
rajani adapa
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i don't think there is a necessity for username and password to be associated with accssing a database
rajani
 
Marcos Maia
Ranch Hand
Posts: 977
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, try to do your catch statements display a more useful message with something like:
catch(SQLException e)
{
e.printStackTrace();
}
and or
catch(SQLException e)
{
System.out.println(e.getMessage());

}
than you shoul be able to debug the errors better.
 
rajani adapa
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I changed the database.now it's working.
But the problem is iam trying to insert into table choices.
if i type,
"insert into choices(bookname, isbnnumber)values('java','1234')"
it's inserting the string java and 1234.
now,
what i want to do is,
i want to insert data where data is a variable whose value is java.
what is wrong with this?
"insert into choices(bookname, isbnnumber)values(data,'1234')"
thanks in advance
rajani
 
rajani adapa
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if i do
"insert into choices(bookname, isbnnumber)values("'"+data+"'",'1234')"
this is the output:
C:\JSDK2.0\examples>javac postparametersservlet.java
postparametersservlet.java:50: unclosed character literal
q="insert into choices(bookname, isbnnumber)values("'"+data+"'",'1234')";
^
postparametersservlet.java:50: unclosed character literal
q="insert into choices(bookname, isbnnumber)values("'"+data+"'",'1234')";
^
postparametersservlet.java:50: unclosed character literal
q="insert into choices(bookname, isbnnumber)values("'"+data+"'",'1234')";
^
postparametersservlet.java:50: unclosed string literal
q="insert into choices(bookname, isbnnumber)values("'"+data+"'",'1234')";
^
4 errors
 
rajani adapa
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry, but now it is,
C:\JSDK2.0\examples>javac postparametersservlet.java
postparametersservlet.java:50: illegal character: \92
q="insert into choices(bookname, isbnnumber)values("\'"+data+"\'",'1234')";
^
postparametersservlet.java:50: unclosed character literal
q="insert into choices(bookname, isbnnumber)values("\'"+data+"\'",'1234')";
^
postparametersservlet.java:50: unclosed character literal
q="insert into choices(bookname, isbnnumber)values("\'"+data+"\'",'1234')";
^
postparametersservlet.java:50: unclosed character literal
q="insert into choices(bookname, isbnnumber)values("\'"+data+"\'",'1234')";
^
postparametersservlet.java:50: unclosed string literal
q="insert into choices(bookname, isbnnumber)values("\'"+data+"\'",'1234')";
^
5 errors
 
Marcos Maia
Ranch Hand
Posts: 977
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
really sorry the correct way is:

"insert into choices(bookname,isbnnumber)values('"+data+"','1234')"

really sorry for wasting your time.


[This message has been edited by Marcos Maia (edited July 18, 2001).]
 
rajani adapa
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank u guys.
bye
rajini
 
No matter how many women are assigned to the project, a pregnancy takes nine months. Much longer than this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic