aspose file tools*
The moose likes JDBC and the fly likes why it is not compiling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "why it is not compiling" Watch "why it is not compiling" New topic
Author

why it is not compiling

Narasimha Raju Naidu
Ranch Hand

Joined: Mar 23, 2007
Posts: 37
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 ]
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30537
    
150

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Narasimha Raju Naidu
Ranch Hand

Joined: Mar 23, 2007
Posts: 37
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30537
    
150

What error message are you getting now?
Narasimha Raju Naidu
Ranch Hand

Joined: Mar 23, 2007
Posts: 37
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30537
    
150

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

Joined: Mar 23, 2007
Posts: 37
really sorry i pasted worng one

now i am giving right code



please tell me what is my mistake
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30537
    
150

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

Joined: Mar 23, 2007
Posts: 37
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: why it is not compiling