2014-05-08 42 views
-7

我的錯誤是:PostgreSQL的3錯誤:無法將應用程序連接到數據庫

May 08, 2014 3:03:16 PM org.apache.catalina.core.StandardWrapperValve invoke 
SEVERE: Servlet.service() for servlet [jsp] in context with path [/Licenta] threw exception [javax.servlet.ServletException: java.lang.ClassNotFoundException: postgresql-9.3-1101.jdbc3] with root cause 
java.lang.ClassNotFoundException: postgresql-9.3-1101.jdbc3 
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1676) 
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521) 
    at java.lang.Class.forName0(Native Method) 
    at java.lang.Class.forName(Unknown Source) 
    at proiect.GetCarte.GetCarte2(GetCarte.java:23) 
    at org.apache.jsp.Carti_jsp._jspService(Carti_jsp.java:112) 
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722) 
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419) 
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391) 
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) 
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240) 
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164) 
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462) 
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164) 
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100) 
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562) 
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) 
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395) 
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250) 
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188) 
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:166) 
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) 
    at java.lang.Thread.run(Unknown Source) 

這裏是我的代碼。

import beans.Carte; 

import com.mysql.jdbc.Statement; 

public class GetCarte { 

    public ArrayList<Carte> GetCarte2() throws ClassNotFoundException, SQLException 
    { 
     ArrayList<Carte> carti = new ArrayList<Carte>(); 
     // TODO Auto-generated method stub 



     // Class.forName("com.mysql.jdbc.Driver"); 
     Class.forName(" postgresql-9.3-1101.jdbc3"); 
     Connection con = DriverManager.getConnection("jdbc:postgresql://localhost:5432/inventarbiblioteca", "root", "password"); 
     Statement st = (Statement) con.createStatement(); 
     ResultSet rs; 
     Carte carte=new Carte(); 

     rs = st.executeQuery("select * from carte"); 

     while (rs.next()) { 
      int identificatorCarte=Integer.parseInt(rs.getString("identificatorCarte")); 
       int ISBN=Integer.parseInt(rs.getString("ISBN")); 
        String titlul=rs.getString("titlul"); 
        String autori=rs.getString("autori"); 
        String editura=rs.getString("editura"); 
        int anAparitie=Integer.parseInt(rs.getString("anAparitie")); 
        int editie=Integer.parseInt(rs.getString("editie")); 
        int pret=Integer.parseInt(rs.getString("pret")); 
        int idDomeniu=Integer.parseInt(rs.getString("idDomeniu")); 
        String observatiiCarte=rs.getString("observatiiCarte"); 
        carte = new Carte (identificatorCarte, ISBN, titlul, autori, editura, anAparitie, editie, pret, idDomeniu, observatiiCarte); 
        System.out.println("adauga carte " + carte.getTitlul()); 
        carti.add(carte); 

     } 

     System.out.println("Titluri:"); 
    for(Carte t : carti) 
    { 
     System.out.println(t.getTitlul()); 
    } 

     return carti; 
} 


    public ArrayList<Carte> GetSearchedCarte (String searched) throws ClassNotFoundException, SQLException 
    { 
     ArrayList<Carte> carti = new ArrayList<Carte>(); 
     // TODO Auto-generated method stub 



     Class.forName("com.mysql.jdbc.Driver"); 
     Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/proiect", "root", "root"); 
     Statement st = (Statement) con.createStatement(); 
     ResultSet rs; 
     Carte carte=new Carte(); 

     rs = st.executeQuery("select * from carte where titlul like '%" + searched + "%'"); 

     while (rs.next()) { 
      int identificatorCarte=Integer.parseInt(rs.getString("identificatorCarte")); 
       int ISBN=Integer.parseInt(rs.getString("ISBN")); 
        String titlul=rs.getString("titlul"); 
        String autori=rs.getString("autori"); 
        String editura=rs.getString("editura"); 
        int anAparitie=Integer.parseInt(rs.getString("anAparitie")); 
        int editie=Integer.parseInt(rs.getString("editie")); 
        int pret=Integer.parseInt(rs.getString("pret")); 
        int idDomeniu=Integer.parseInt(rs.getString("idDomeniu")); 
        String observatiiCarte=rs.getString("observatiiCarte"); 
        carte = new Carte (identificatorCarte, ISBN, titlul, autori, editura, anAparitie, editie, pret, idDomeniu, observatiiCarte); 
        System.out.println("adauga carte " + carte.getTitlul()); 
        carti.add(carte); 

     } 

     System.out.println("Titluri:"); 
    for(Carte t : carti) 
    { 
     System.out.println(t.getTitlul()); 
    } 

     return carti; 
} 

    public Carte GetCarteByISBN (int isbn) throws ClassNotFoundException, SQLException 
    { 

     // TODO Auto-generated method stub 
     Carte t = new Carte(); 



     Class.forName("com.mysql.jdbc.Driver"); 
     Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/proiect", "root", "root"); 
     Statement st = (Statement) con.createStatement(); 
     ResultSet rs; 
     Carte carte = new Carte(); 

     rs = st.executeQuery("select * from carte where identificatorCarte=" + isbn); 

     if (rs.next()) { 
      int identificatorCarte=Integer.parseInt(rs.getString("identificatorCarte")); 
       int ISBN=Integer.parseInt(rs.getString("ISBN")); 
        String titlul=rs.getString("titlul"); 
        String autori=rs.getString("autori"); 
        String editura=rs.getString("editura"); 
        int anAparitie=Integer.parseInt(rs.getString("anAparitie")); 
        int editie=Integer.parseInt(rs.getString("editie")); 
        int pret=Integer.parseInt(rs.getString("pret")); 
        int idDomeniu=Integer.parseInt(rs.getString("idDomeniu")); 
        String observatiiCarte=rs.getString("observatiiCarte"); 
        carte = new Carte (identificatorCarte, ISBN, titlul, autori, editura, anAparitie, editie, pret, idDomeniu, observatiiCarte); 
        System.out.println("adauga carte " + carte.getTitlul()); 



     } 

     return carte; 
} 
} 
+4

SO不是調試服務 –

+0

驅動程序未加載。下載postgresql的jdbc驅動程序並將其放在類路徑中。這是鏈接http://jdbc.postgresql.org/download.html –

+0

這樣的問題怎麼會得到upvote .. –

回答

1

您應該將JDBCPostgreSQL驅動程序添加到類路徑中。

0

您使用的是PostgreSQL JDBC驅動程序的錯誤名稱。

的錯誤是在這裏:

Class.forName(" postgresql-9.3-1101.jdbc3"); 

postgressql-9.3.1101.jdbc3是JAR的名稱,而不是類的名稱。您需要加載班級:

Class.forName("org.postgresql.Driver"); 

另請參見http://jdbc.postgresql.org/documentation/head/load.html

相關問題