/    Sign up×
Community /Pin to ProfileBookmark

prob in radio button

i have a radio button, i want to do that if i select that radio button then it displays Y in database and shows it, otherwise it shows N.

In my form it doesn’t shows Y or N… but it shows hold(which is the value of hold button)..

In my oracle database its data type is CHAR(1)…

this is the radio button:

Hold <input type=radio name=”hold” value=”hold” >

and my form code is as follow:

<html>
<body>
<table>
<tr>
<td>

<%@ page import=”javax.servlet.*” %>
<%@ page import=”javax.servlet.http.*
” %>
<%@ page language=”java” import=”java.sql.*” %>

<%
try {

Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);
Connection conn=DriverManager.getConnection(“jdbc:odbc:pf”,”scott”,”ttlscott”);
System.out.println(“got connection”);

%>

<%

String action = request.getParameter(“action”);
if (action != null && action.equals(“save”)) {
conn.setAutoCommit(false);

PreparedStatement pstmt = conn.prepareStatement(
(“INSERT INTO pay_header VALUES (?)”));

char pay_type;

if (request.getParameter(“pay_type”) != null) {pay_type = ‘Y’;} else {pay_type = ‘N’;}
pstmt.setString(1,pay_type);

pstmt.executeUpdate();
conn.commit();
conn.setAutoCommit(true);
}

%>

<%

Statement statement = conn.createStatement();

ResultSet rs = statement.executeQuery
(“SELECT * FROM pay_header “);

%>

<table>
<tr>
<tr>
<form action=”payment_save1.jsp” method=”get”>
<input type=”hidden” value=”save” name=”action”>
<th><input value=”<%= request.getParameter(“hold”) %>” name=”pay_type” size=”15″></th>
<th><input type=”submit” value=”save”></th>
</form>
</tr>

<%

while ( rs.next() ) {

%>

<tr>
<form action=”payment_save1.jsp” method=”get”>
<input type=”hidden” value=”save” name=”action”>
<td><input value=”<%= rs.getString(“pay_type”) %>” name=”pay_type”></td>
<td><input type=”submit” value=”save”></td>
</form>
</tr>

<%
}
%>
</table>

<%
// Close the ResultSet
rs.close();

// Close the Statement
statement.close();

// Close the Connection
conn.close();
} catch (SQLException sqle) {
out.println(sqle.getMessage());
} catch (Exception e) {
out.println(e.getMessage());
}
%>
</td>
</tr>
</body>
</html>

actually error is coming like that..

HTTP Status 500 –


——————————————————————————- –

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 27 in the jsp file: /payment_voucher/payment_save1.jsp
Generated servlet error:
D:Program FilesApache Software FoundationTomcat 5.0workCatalinalocalhostabhiorgapachejsppayment_005fvoucherpayment_005 fsave1_jsp.java:101: setString(int,java.lang.String) in java.sql.PreparedStatement cannot be applied to (int,char)
pstmt.setString(3,pay_post);
^
1 error

org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.j ava:84)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:332)
org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:437)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:497)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:476)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:464)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:511)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:295)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

note The full stack trace of the root cause is available in the Apache Tomcat/5.0.30 logs.


——————————————————————————- –

Apache Tomcat/5.0.30

to post a comment
Java

1 Comments(s)

Copy linkTweet thisAlerts:
@ray326Dec 03.2004 — You have 2 primary and serious problems. First, you should not be doing database stuff in a JSP; that belongs on the other side of a business object on the other side of a servlet that handles the form's action. Second, your HTML is awful. You only need one form for that page and you're asking about the value of a radio button and you don't even have a radio button set defined on the page. Also, radio buttons are MULTIPLES so you don't have A radio button you have several with the same name. Finally, you need to read the API docs on PreparedStatement to see why the compiler is telling you:

setString(int,java.lang.String) in java.sql.PreparedStatement cannot be applied to (int,char)

pstmt.setString(3,pay_post);

^

1 error

Hint: a char is not a String.
×

Success!

Help @abhit_kumar spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.15,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...