Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Juno not import sql driver
Juno not import sql driver [message #1017217] Mon, 11 March 2013 08:21
pippuccio76 ... is currently offline pippuccio76 ...Friend
Messages: 9
Registered: November 2012
Junior Member
Hi , i have a symple jsp page :

  <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>

<%@ page import="java.sql.*" %>
    
-
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" >
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Pagina 2 elenco</title>
</head>
<body>

    <jsp:useBean id="db" scope="page" class="classi.Db" ></jsp:useBean>
    
    
        <%
        //db.connettiAlDatabase("localhost", "java_db"," root", "root");
        Connection connect= db.get_connessione();
			
		out.println(connect);
        
       // Class.forName("com.mysql.jdbc.Driver")  ;  	// Imposta la connessione al server e al database
       // Connection connect = DriverManager.getConnection("jdbc:mysql://localhost/java_db","root","root");

        String sql = "select * from utenti";
        
      /*  Statement  stmt = connect.createStatement();
        ResultSet rs = stmt.executeQuery(sql);
		
        String r = "<div><h1>Elenco dati utenti</h1><table>";
        
        rs.first(); // si porta all'inizio del resulset
        
        String a1,a2;
		do {
			a1="<a href='modificaUtente.jsp?idutente="+rs.getInt("id")+"'>Mod</a>";
                        a2="<a href=\"elimina_utente.jsp?idutente="+rs.getInt("id")+"\"onclick=\"return confirm('Procedo con la cancellazione');\">Elimina</a>";
                        
			r += "<tr><td>" + rs.getString("nome") + "</td>";
			r += "<td>" + rs.getString("cognome") + "</td>";
                        r += "<td>" +a1+"</td>";
                        r += "<td>" +a2+"</td></tr>";
			//String nome = rs.getString("nome");
			//String cognome = rs.getString("cognome");

			//out.println("nome : " + nome);
			//out.println("cognome : " + cognome);

		}while(rs.next()); // scorre i record
		r += "</table>";
		out.print(r);
        
        connect.close();
*/
        %>
	<a href="indexjsp">Torna a index</a>
</body>
</html>




and a class in the same project :

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package classi;


import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Frame 11
 */
public class Db {
   private Connection connect;
   private int id;
   private String prova;//per testare la stringa per connettersi
   private String server, nomedb, username, password;
   
   public Db(){
     try { 
                try {
                    Class.forName("com.mysql.jdbc.Driver")  ;  	// Imposta la connessione al server e al database
                } catch (Exception e) {
                	 throw new RuntimeException("Oops, failed to initialize the driver");                }
         //       prova="jdbc:mysql://"+server+"/"+nomedb+",\""+username+"\",\""+password+"\"";
                connect = DriverManager.getConnection("jdbc:mysql://localhost/java_db","root","root");
     			} catch (SQLException ex) {
               Logger.getLogger(Db.class.getName()).log(Level.SEVERE, null, ex);
     			}
       
   }
       public void connettiAlDatabase(String server,String nomeDb,String username,String password){
            try { 
                try {
                    Class.forName("com.mysql.jdbc.Driver")  ;  	// Imposta la connessione al server e al database
                } catch (ClassNotFoundException ex) {
                    Logger.getLogger(Db.class.getName()).log(Level.SEVERE, null, ex);
                }
         //       prova="jdbc:mysql://"+server+"/"+nomedb+",\""+username+"\",\""+password+"\"";

             // Imposta la connessione al server e al database
    		    connect = DriverManager.getConnection("jdbc:mysql://" + server + "/" + nomeDb +"?" + "user="+username+"&password="+password); // N.B. la password vuota si scrive password=
            
            } catch (SQLException ex) {
               Logger.getLogger(Db.class.getName()).log(Level.SEVERE, null, ex);
           }
           
       }
       
       public Connection get_connessione(){
           return connect;
       }
       
       public ResultSet getDati(Connection connect,String sql){
                this.connect=connect;
                Statement stmt;
                ResultSet rs=null;
            try {                      
                stmt = connect.createStatement();
                rs = stmt.executeQuery(sql);

            } catch (SQLException ex) {
                Logger.getLogger(Db.class.getName()).log(Level.SEVERE, null, ex);
            }

                 return rs;
       }
       
       
       public void eliminazione(String id,String tabelladb){
            try {
                
                this.id=Integer.parseInt(id);
                String nometabella=tabelladb;
                String sql = "delete  from "+nometabella+" where id="+id;

               Statement  stmt = connect.createStatement();

               stmt.executeUpdate(sql);
            } catch (SQLException ex) {
                Logger.getLogger(Db.class.getName()).log(Level.SEVERE, null, ex);
            }
           
       } 
      /* 
       public String getProva(){
           return prova;
       }
       */
}
  


i have imported the external jar my-sql connector in the project but when i run it i have :

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: java.lang.RuntimeException: Oops, failed to initialize the driver
	org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:534)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:457)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
root cause

java.lang.RuntimeException: Oops, failed to initialize the driver
	classi.Db.<init>(Db.java:27)
	org.apache.jsp.pagina2_jsp._jspService(pagina2_jsp.java:72)
	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:391)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
	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.12 logs.

Apache Tomcat/7.0.12

Previous Topic:Juno SR2 Checksum Not Matching for eclipse-jee-juno-SR2-win32-x86_64.zip
Next Topic:Doubts
Goto Forum:
  


Current Time: Tue Dec 23 05:24:04 GMT 2014

Powered by FUDForum. Page generated in 0.01504 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software