• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

why it is not compiling

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
once again hi to all,

now i am facing with new problem since 5 days. now i am putting in front ao ypu people. can any one tell where i am wrong.

here i am trying to get the data from the database mysql using jsp. here i am using package concept of java and i wrote two java programs namely connect.java which is placed inside connection package and SqlBean.java which is placed inside package sq.

i am placing my code

connect.java
--------------
package connection;
import java.sql.DriverManager;
import java.sql.Connection;
import java.io.*;
public class connect
{
Connection conn;
public connect()
{
try{
Class.forName("com.mysql.jdbc.Driver");
}
catch(Exception e)
{
System.out.println(e);
}
}
public Connection getConnection()
{
try{
conn=DriverManager.getConnection("mysql:mysql://localhost/hello","root","root");
}catch(Exception e)
{
System.out.println(e);
}
return conn;
}
}
---------------------------

SqlBean.java
------------
package sq;

import connection.*;
import java.sql.*;

public class SqlBean
{
Connection con=null;

public SqlBean()
{
connect c=new connect();
con=c.getConnection();
}
// Insert the records into database
public String insert(String query)
{
int i=0;
try
{
//Statement st=con.createStatement();
//i=st.executeUpdate(query);
//System.out.println("hi");
//return query;
}
catch(Exception e)
{
System.out.println(e);
}

return query;
}

// it is used to select the records based on Query
public ResultSet selection(String query)
{
ResultSet rs=null;
*try
{
Statement st=con.createStatement();
rs=st.executeQuery(query);
//return rs;
}
catch(Exception e)
{
System.out.println(e);
}

return rs;
}

// to close the connection (con)
public void close()
{
try
{
if(con!=null)
{
con.close();
}
}catch(Exception e)
{
System.out.println(e);
}
}
}
------------------------------------------

and my jsp code as follows

tes.jsp
--------
<%@ page import="java.sql.*" session="false" %>
<jsp:useBean id="s" class="sq.SqlBean" scope="page" />
<%!String str1;%>
<%
str1="select * from how";
ResultSet rs=s.select(str1);
//String qq=s.insert("hello")
//out.println(qq);
while (rs.next())
{
//here code to retrive all the fields ok
}
%>
--------------------------------------

can any one tell wher i am doing mistake.
i am not getting any errors while compailing .java programs

Exceptions what i am getting as follows

exception

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

An error occurred at line: 6 in the jsp file: /te.jsp
The method select(String) is undefined for the type SqlBean
3: <%!String str1;%>
4: <%
5: str1="select * from how";
6: ResultSet rs=s.select(str1);
7: //String qq=s.insert("hello")
8: //out.println(qq);
9: while (rs.next())


Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:85)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:415)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:308)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:273)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:308)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


waiting for you people reply

[edited subject to be more descriptive - was "can any one help me"]

[ April 07, 2007: Message edited by: Jeanne Boyarsky ]
[ April 07, 2007: Message edited by: Narasimha Raju Naidu ]
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Narasimha,
In SqlBean, the method is called selection() and in the JSP it is called select().

Note that it is good practice to make JDBC calls from Java rather than putting scriptlets in the JSP. It is easier to read, maintain and gives clearer error messages.
 
Narasimha Raju Naidu
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for your reply,


i edited my code but no use same error what i got previously now also getting.
as you said "it is good practice to make JDBC calls from Java rather than putting scriptlets in the JSP. It is easier to read, maintain and gives clearer error messages". thanks for your good sugession. here i want to say one thing i placed my jdbc code in .java files only and i am accessing the results only in jsp and the program what i placed in my requset itself is a java code, using .class files i am trying to access my records. at this place only i am facing problem. please go through once all programs. i am waiting for your reply

regards
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What error message are you getting now?
 
Narasimha Raju Naidu
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i am getting the following exceptions

exception

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

An error occurred at line: 6 in the jsp file: /te.jsp
The method select(String) is undefined for the type SqlBean
3: <%!String str1;%>
4: <%
5: str1="select * from how";
6: ResultSet rs=s.select(str1);
7: //String qq=s.insert("hello")
8: //out.println(qq);
9: while (rs.next())


Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:85)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:415)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:308)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:273)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:308)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's the same message as before.

SqlBean has the method signature:
public ResultSet selection(String query)

but the JSP calls:
ResultSet rs=s.select(str1);
 
Narasimha Raju Naidu
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
really sorry i pasted worng one

now i am giving right code



please tell me what is my mistake
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Narasimha,
There isn't enough stacktrace to see what the error is. Your choices are:
1) Find out how to see the full message (maybe look at the logs)
2) Gradually comment out code until you see which line has the error
3) Copy paste the code to a Java file to see the compiler error
 
Narasimha Raju Naidu
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for your reply,


when i am using the same code(JDBC code written inside jsp code) with jsp working and i am getting records from database but when ever i am trying with .class files with jsp i am getting the following errors
reply
    Bookmark Topic Watch Topic
  • New Topic