aspose file tools*
The moose likes JDBC and the fly likes SQL Exception :general error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "SQL Exception :general error" Watch "SQL Exception :general error" New topic
Author

SQL Exception :general error

vishal mishra
Ranch Hand

Joined: Jul 12, 2010
Posts: 103
hi friends
i have just started learning jsp.
some body please help me in correcting following code

<%@ page import= "java.sql.*" %>
<%
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn=null;
conn= DriverManager.getConnection("jdbcdbc:data","","");
conn.close();
}catch(Exception e){
out.println(e.toString());
}



%>

I was trying to access MS-Access DB
but Code above has Genereted

SQLException:General Error

PLEASE HELP ME!!1
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2503
    
    8

Welcome to JavaRanch, vishal .
Your jsp engine might have more info on this SQLException in its error log.

By the way, embedding database logic inside a jsp is not recommended. The person who is telling you how to learn jssp has started with a bad example

OCUP UML fundamental and ITIL foundation
youtube channel
vishal mishra
Ranch Hand

Joined: Jul 12, 2010
Posts: 103
Thank you For replying .

I am learning JSP myself.That Code was Given in the text book of Indra Gandhi Open University(IGNOU) . I am using Tomcat Server and trying to Learn Database Connectivity
through JSP. Please tell me how can I do it.


Previous Code With Error is given below. -:



<%@ page import= "java.sql.*" %>
<%

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn=null;
conn= DriverManager.getConnection("jdbcdbc:data","","");
conn.close();

%>



error:-


type Exception report

message

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

exception

org.apache.jasper.JasperException: An exception occurred processing JSP page /ch1.jsp at line 6

3:
4: Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
5: Connection conn=null;
6: conn= DriverManager.getConnection("jdbcdbc:data","","");
7: conn.close();
8:
9: %>


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:401)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
root cause

javax.servlet.ServletException: java.sql.SQLException: General error
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:862)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791)
org.apache.jsp.ch1_jsp._jspService(ch1_jsp.java:69)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
root cause

java.sql.SQLException: General error
sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(Unknown Source)
sun.jdbc.odbc.JdbcOdbcConnection.initialize(Unknown Source)
sun.jdbc.odbc.JdbcOdbcDriver.connect(Unknown Source)
java.sql.DriverManager.getConnection(Unknown Source)
java.sql.DriverManager.getConnection(Unknown Source)
org.apache.jsp.ch1_jsp._jspService(ch1_jsp.java:60)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.24 logs.


PLEASE HELP ME !!
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2503
    
    8

The exception happens when you try to connect to the database:

sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(Unknown Source)


Check if the odbc datasource exists, and that it works
Check if the odbc datasource is a system datasource, not a user datasource.
vishal mishra
Ranch Hand

Joined: Jul 12, 2010
Posts: 103


It is still not working.

Even strange thing is happening here.

When I wrote the code in a JAVA class and compiled and execute it using NetBeans IDE ,

connection got established.

And in either case when I tried to establish the connection through JSP it was giving the same error.

Please Suggest me what Should I do???


JAVA CLASS given below-:


class Db{

public static void main(String args[]) throws
ClassNotFoundException,SQLException{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn=null;
conn= DriverManager.getConnection("jdbcdbc:data","","");
System.out.println("Connection Successfull !!!");
conn.close();

}


}
vishal mishra
Ranch Hand

Joined: Jul 12, 2010
Posts: 103
Sorry!!! That was a mistake
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2503
    
    8

I have asked you to check two things in my previous post:

Check if the odbc datasource exists, and that it works
Check if the odbc datasource is a system datasource, not a user datasource.

Did you do that?

Netbeans is a desktop application, and runs under your windows user account.
Tomcat is a service, and probably does not run under your windows user account.
User ODBC datasources can only be found, and used, by your windows user account.
System ODBC datasources can be used by all user accounts.
vishal mishra
Ranch Hand

Joined: Jul 12, 2010
Posts: 103
I have mentioned earlier-: "It is still not working" that means I have tried both the options .

There is existence of data source.

Data Source is a System Data Source, not an User data Source.

Now,

Please tell me the way to resolve this problem.

It is generating the same error-:

type Exception report

message

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

exception

org.apache.jasper.JasperException: javax.servlet.ServletException: java.sql.SQLException: General error
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:491)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:401)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
root cause

javax.servlet.ServletException: java.sql.SQLException: General error
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:862)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791)
org.apache.jsp.ch1_jsp._jspService(ch1_jsp.java:69)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
root cause

java.sql.SQLException: General error
sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(Unknown Source)
sun.jdbc.odbc.JdbcOdbcConnection.initialize(Unknown Source)
sun.jdbc.odbc.JdbcOdbcDriver.connect(Unknown Source)
java.sql.DriverManager.getConnection(Unknown Source)
java.sql.DriverManager.getConnection(Unknown Source)
org.apache.jsp.ch1_jsp._jspService(ch1_jsp.java:60)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
vishal mishra
Ranch Hand

Joined: Jul 12, 2010
Posts: 103
PLEASE Help
srividya varada
Greenhorn

Joined: Oct 03, 2012
Posts: 1
<%@page import="java.sql.*"%>
<%@page import="java.util.*"%>
<%@page import="java.lang.*"%>
<%@page import="java.util.Properties"%>
<%@page import="javax.mail.Message"%>
<%@page import="javax.mail.MessagingException"%>
<%@page import="javax.mail.PasswordAuthentication"%>
<%@page import="javax.mail.Session"%>
<%@page import="javax.mail.Transport"%>
<%@page import="javax.mail.internet.InternetAddress"%>
<%@page import="javax.mail.internet.MimeMessage"%>
<%@page import="javax.mail.AuthenticationFailedException"%>
<%@page import="javax.mail.internet.AdrressException.*"%>
<%@page import="javax.mail.Authenticator"%>


<%

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbcdbc:mini","","");

String email="";


String recruiter=request.getParameter("recruiter");
String post=request.getParameter("post");
String qual=request.getParameter("qual");
String ld=request.getParameter("ld");
String ed=request.getParameter("ed");
String age=request.getParameter("age");
String sa=request.getParameter("sa");



Statement st1,st=con.createStatement();
ResultSet rs=st.executeQuery("select count(*) as c from job");

rs.next();
int serailnumber=rs.getInt(1)+1;
System.out.print(serailnumber);
String s="";
int a=0;
String b;
String c;
st=con.createStatement();
st1=con.createStatement();
ResultSet rs1=st.executeQuery("select serialnumber,Recruiter,Postname from job ");
while(rs1.next())
{
a=rs1.getInt(1)+1;
b=rs1.getString(2);
c=rs1.getString(3);
s="update job set serialnumber="+a+" where Recruiter='"+b+"' AND Postname='"+c+"'";
st1.executeUpdate(s);
}
PreparedStatement pst=con.prepareStatement("insert into job values(?,?,?,?,?,?,?,?)");

pst.setInt(1,1);
pst.setString(2,recruiter);
pst.setString(3,post);
pst.setString(4,qual);
pst.setString(5,ld);
pst.setString(6,ed);
pst.setString(7,age);
pst.setString(8,sa);



pst.executeUpdate();


final String pwd=")(A%!A)%A@,502,503,587";
System.out.print("hello");

rs=st.executeQuery("select email from Table1");
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");

try{
Session sess = Session.getInstance(props,new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("recent.notifications@gmail.com",pwd);}});

while(rs.next())
{

email=rs.getString(1);
Message message = new MimeMessage(sess);
message.setFrom(new InternetAddress("recent.notifications@gmail.com"));
message.setRecipients(Message.RecipientType.TO,InternetAddress.parse(email));
message.setSubject("New Notification for JOB");


message.setText("My Dear frnds,New Job Notification for you..\n Recruiter:"+recruiter+"\nPost: "+post+"\n Qualification: "+qual+"\n Last date For application: "+ld+"For details you can visit "+sa+" website \n All the best frnds.........");
Transport.send(message);

System.out.println("Done");
}

con.close();
}
catch (MessagingException e) {throw new RuntimeException(e);}
%>
Notifications sent Successfully...<br>
<a href="home.html">Click Here</a> to redirect to Home Page....






























when i execute this , i got errors like


e Exception report

message

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

exception

org.apache.jasper.JasperException: javax.servlet.ServletException: java.sql.SQLException: General error
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:534)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:442)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
root cause

javax.servlet.ServletException: java.sql.SQLException: General error
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:911)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:840)
org.apache.jsp.SendMailSSL_jsp._jspService(SendMailSSL_jsp.java:188)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
root cause

java.sql.SQLException: General error
sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6985)
sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7113)
sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(JdbcOdbc.java:3109)
sun.jdbc.odbc.JdbcOdbcStatement.execute(JdbcOdbcStatement.java:337)
sun.jdbc.odbc.JdbcOdbcStatement.executeUpdate(JdbcOdbcStatement.java:287)
org.apache.jsp.SendMailSSL_jsp._jspService(SendMailSSL_jsp.java:126)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.16 logs.

Apache Tomcat/7.0.16
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SQL Exception :general error