IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Servlets/JSP Java Discussion :

[JSP-SQL Server]Comment afficher des données dans les pages JSP


Sujet :

Servlets/JSP Java

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Avril 2006
    Messages
    116
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2006
    Messages : 116
    Points : 63
    Points
    63
    Par défaut [JSP-SQL Server]Comment afficher des données dans les pages JSP
    Bonsoir,

    Je viens de me mettre à Java je viens du PHP, auriez-vous un exemple de la manière d'afficher les données issues d'une table SQL Server ou autres dans une table ...

    Je n'ai pas trouvé dans la FAQ

    Merci de votre aide

  2. #2
    Membre averti
    Avatar de dtavan
    Profil pro
    Inscrit en
    Juin 2002
    Messages
    162
    Détails du profil
    Informations personnelles :
    Âge : 54
    Localisation : France

    Informations forums :
    Inscription : Juin 2002
    Messages : 162
    Points : 381
    Points
    381
    Par défaut
    j'ai trouvé ca sur Sun.com

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    JavaServer PagesTM Standard Tag Library (JSTL) Specification ("Specification")
    Version: 1.0
    Status: FCS
    Release: June 11, 2002
    :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
     
    Data Source
    SQL actions operate on a data source, as defined by the Java class
    javax.sql.DataSource. A DataSource object provides connections to the
    physical data source it represents. Within the context of a Connection retrieved
    from the DataSource, SQL statements are executed and results are returned.
    10-130 JSTL 1.0 • June 2002
    A data source can be specified explicitly via the dataSource attribute in SQL
    actions, or it can be totally transparent to a page author by taking advantage of the
    data source configuration setting (javax.servlet.jsp.jstl.sql.dataSource).
    There are two ways a data source can be specified as a string.
    The first way is through a JNDI relative path, assuming a container supporting
    JNDI. For example, with the absolute JNDI resource path java:comp/env/jdbc/
    myDatabase, the JNDI relative path to the data source resource would simply be
    jdbc/myDatabase, given that java:comp/env is the standard JNDI root for a
    J2EE application.
    The second way is by specifying the parameters needed by the JDBC
    DriverManager class, using the following syntax (see Section 10.6 for details on the
    JDBC parameters)
    url[,[driver][,[user][,password]]]
    For example,
    jdbc:mysql://localhost/,org.gjt.mm.mysql.Driver
    where the database has been setup for access without any username or password. If
    the ‘,’ character occurs in any of the JDBC parameters, it can be escaped by ‘\’. The
    character ‘\’ itself can be escaped in the same way.
    While the JDBC DriverManager class provides a low cost way to use SQL actions,
    it is not recommended to use it other than for prototyping purposes because it does
    not provide connection management features one can expect from a properly
    designed DataSource object.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
     
    <sql:query var="customers" dataSource="${dataSource}">
    SELECT * FROM customers
    WHERE country = ’China’
    ORDER BY lastname
    </sql:query>
    <table>
    <c:forEach var="row" items="${customers.rows}">
    <tr>
    <td><c:out value="${row.lastName}"/></td>
    <td><c:out value="${row.firstName}"/></td>
    <td><c:out value="${row.address}"/></td>
    </tr>
    </c:forEach>
    </table>
    <table>
    <!-- column headers -->
    <tr>
    <c:forEach var=”columnName” items=”${result.columnNames}”>
    <th><c:out value="${columnName}"/></th>
    </c:forEach>
    </tr>
    <!-- column data -->
    <c:forEach var="row" items="${result.rowsByIndex}">
    <tr>
    <c:forEach var="column" items="${row}">
    <td><c:out value="${column}"/></td>
    </c:forEach>
    </tr>
    </c:forEach>
    </table>
    par contre je n'ai pas trouvé pour SQL Server
    David Tavan

    Mon blog 1
    Mon blog 2

  3. #3
    Membre averti
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    352
    Détails du profil
    Informations personnelles :
    Âge : 57
    Localisation : Suisse

    Informations forums :
    Inscription : Janvier 2006
    Messages : 352
    Points : 445
    Points
    445
    Par défaut
    En fait tu as trouvé la réponse à ta question, il te suffit de remplacer l'url et le driver afin de pointer sur ta base SQL Server.

    Je ne sais pas quel driver tu utilises mais il existe Jtds qui est gratuit et qui fonctionne très bien.

    Jacques Desmazières

  4. #4
    Membre du Club
    Profil pro
    Inscrit en
    Avril 2006
    Messages
    116
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2006
    Messages : 116
    Points : 63
    Points
    63
    Par défaut
    Merci pour cette réponse davidyannick, mais est-il possible de faire du binding comme en ASP .NET par exemple ?

    du style
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <td><%= table(enregistrement) %></td>

  5. #5
    Membre du Club
    Profil pro
    Inscrit en
    Avril 2006
    Messages
    116
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2006
    Messages : 116
    Points : 63
    Points
    63
    Par défaut
    j'ai essayé ceci :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
     
    <%@page contentType="text/html"%>
    <%@page pageEncoding="UTF-8"%>
    <%@page import="com.microsoft.sqlserver.jdbc.SQLServerDataSource"%>
    <%@page import="java.sql.*"%>
    <%--
    The taglib directive below imports the JSTL library. If you uncomment it,
    you must also add the JSTL library to the project. The Add Library... action
    on Libraries node in Projects view can be used to add the JSTL 1.1 library.
    --%>
     
    <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 
    <%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>
     
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">
     
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>JSP Page</title>
        </head>
        <body>
     
        <h1>JSP Page</h1>
     
     
        <%--
        This example uses JSTL, uncomment the taglib directive above.
        To test, display the page like this: index.jsp?sayHello=true&name=Murphy
        --%>
        <%--
        <c:if test="${param.sayHello}">
            <!-- Let's welcome the user ${param.name} -->
            Hello ${param.name}!
        </c:if>
        --%>
       <sql:query var="sqlserver" dataSource="jdbc:sqlserver://localhost:1433;databaseName=AdventureWorks;user=***;password=***;" >
            SELECT * FROM Person.Address
       </sql:query>
     
           <table>
        <c:forEach var="row" items="${Person.Adress.rows}">
        <tr>
        <td><c:out value="${row.City}"/></td>
        <td><c:out value="${row.PostalCode}"/></td>
        <td><c:out value="${row.AdressLine1}"/></td>
        </tr>
        </c:forEach>
        </table>
        <table>
        <!-- column headers -->
        <tr>
        <c:forEach var="columnName" items="${result.columnNames}">
        <th><c:out value="${columnName}"/></th>
        </c:forEach>
        </tr>
        <!-- column data -->
        <c:forEach var="row" items="${result.rowsByIndex}">
        <tr>
        <c:forEach var="column" items="${row}">
        <td><c:out value="${column}"/></td>
        </c:forEach>
        </tr>
        </c:forEach>
        </table>
     
        </body>
    </html>
    Mais j'ai un message d'erreur :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
     
    Etat HTTP 500 - 
     
    --------------------------------------------------------------------------------
     
    type Rapport d'exception
     
    message 
     
    description Le serveur a rencontré une erreur interne () qui l'a empêché de satisfaire la requête.
     
    exception 
     
    javax.servlet.ServletException: javax.servlet.jsp.JspException: Unable to get connection, DataSource invalid: "java.sql.SQLException: No suitable driver"
    	org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:930)
    	org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:863)
    	org.apache.jsp.index_jsp._jspService(index_jsp.java:128)
    	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
    	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:353)
    	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:409)
    	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:317)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
    	com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:73)
    	com.sun.enterprise.web.VirtualServerPipeline.invoke(VirtualServerPipeline.java:120)
    	org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:231)
    	com.sun.enterprise.web.connector.grizzly.ProcessorTask.invokeAdapter(ProcessorTask.java:667)
    	com.sun.enterprise.web.connector.grizzly.ProcessorTask.processNonBlocked(ProcessorTask.java:574)
    	com.sun.enterprise.web.connector.grizzly.ProcessorTask.process(ProcessorTask.java:844)
    	com.sun.enterprise.web.connector.grizzly.ReadTask.executeProcessorTask(ReadTask.java:287)
    	com.sun.enterprise.web.connector.grizzly.ReadTask.doTask(ReadTask.java:212)
    	com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:252)
    	com.sun.enterprise.web.connector.grizzly.WorkerThread.run(WorkerThread.java:75)
     
     
    cause mère 
     
    javax.servlet.jsp.JspException: Unable to get connection, DataSource invalid: "java.sql.SQLException: No suitable driver"
    	org.apache.taglibs.standard.tag.common.sql.QueryTagSupport.getConnection(QueryTagSupport.java:285)
    	org.apache.taglibs.standard.tag.common.sql.QueryTagSupport.doStartTag(QueryTagSupport.java:168)
    	org.apache.jsp.index_jsp._jspx_meth_sql_query_0(index_jsp.java:147)
    	org.apache.jsp.index_jsp._jspService(index_jsp.java:96)
    	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
    	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:353)
    	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:409)
    	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:317)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
    	com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:73)
    	com.sun.enterprise.web.VirtualServerPipeline.invoke(VirtualServerPipeline.java:120)
    	org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:231)
    	com.sun.enterprise.web.connector.grizzly.ProcessorTask.invokeAdapter(ProcessorTask.java:667)
    	com.sun.enterprise.web.connector.grizzly.ProcessorTask.processNonBlocked(ProcessorTask.java:574)
    	com.sun.enterprise.web.connector.grizzly.ProcessorTask.process(ProcessorTask.java:844)
    	com.sun.enterprise.web.connector.grizzly.ReadTask.executeProcessorTask(ReadTask.java:287)
    	com.sun.enterprise.web.connector.grizzly.ReadTask.doTask(ReadTask.java:212)
    	com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:252)
    	com.sun.enterprise.web.connector.grizzly.WorkerThread.run(WorkerThread.java:75)
     
     
    note La trace complète de la cause mère de cette erreur est disponible dans les fichiers journaux de Sun Java System Application Server Platform Edition 9.0.
     
     
    --------------------------------------------------------------------------------
     
    Sun Java System Application Server Platform Edition 9.0
    J'ai vraiment besoin d'aide sur ce coup Merci

  6. #6
    Membre confirmé Avatar de Jabbal'H
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Octobre 2004
    Messages
    403
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2004
    Messages : 403
    Points : 580
    Points
    580
    Par défaut
    Il ne trouve pas les drivers de ton server SQL apparement.

    Si tu veux j'utilise cà, mais c'est codé dans une classe :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    private String driver = "macromedia.jdbc.sqlserver.SQLServerDriver";
    	private String url = "jdbc:macromedia:sqlserver://localhost:1433;"
    						+ "user=***;password=****;DatabaseName=xxxxx";
    	private Connection cnx = null;
    	private Statement st=null;
     
    	public void init(){
     
     
    		try {
     
    			Class.forName(driver);
    			cnx = DriverManager.getConnection(url);		
    			st = cnx.createStatement();
     
    		}
    		catch (SQLException ex) {
    			System.out.println("init : " + ex.getMessage().toString());
    		}
    		catch (ClassNotFoundException ex) {
    			System.out.println("init : " + ex.getMessage().toString());
    		}
     
    	}
    Par contre c'est lié à un server jrun
    Donc je suis pas sur que cà t'aide beaucoup, mais je crois qu'il faut dans n'importe quel cas faire la liaison entre ton server SQL et ton server Java

    Tu as quel server ?
    " Je préfère comprendre les gens qui ne me comprennent pas "

  7. #7
    Membre du Club
    Profil pro
    Inscrit en
    Avril 2006
    Messages
    116
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2006
    Messages : 116
    Points : 63
    Points
    63
    Par défaut
    j'utilise netbeans 5.5 beta 2 et Sun Java System Application Server Platform Edition 9.0

    Je suis vraiment un débutant avec les jsp... J'ai fait comme toi, j'ai créé une classe mais comment l'utiliser dans ma page jsp ?

    Désolé mais newbie je suis

  8. #8
    Membre averti
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    352
    Détails du profil
    Informations personnelles :
    Âge : 57
    Localisation : Suisse

    Informations forums :
    Inscription : Janvier 2006
    Messages : 352
    Points : 445
    Points
    445
    Par défaut
    As-tu rajouté le driver dans le path de ton WAR. Un des moyens est de rajouter le jar du driver dans le WAR dans le répertoire WEB-INF/lib.

    Jacques Desmazières

  9. #9
    Membre du Club
    Profil pro
    Inscrit en
    Avril 2006
    Messages
    116
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2006
    Messages : 116
    Points : 63
    Points
    63
    Par défaut
    Citation Envoyé par Jacques - 06
    As-tu rajouté le driver dans le path de ton WAR. Un des moyens est de rajouter le jar du driver dans le WAR dans le répertoire WEB-INF/lib.

    Jacques Desmazières
    oui je l'ai ajouté

  10. #10
    Membre confirmé Avatar de Jabbal'H
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Octobre 2004
    Messages
    403
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2004
    Messages : 403
    Points : 580
    Points
    580
    Par défaut
    J'ai jamais utilisé Sun Java System Application Server Platform Edition 9.0 désolé.
    Par contre pour utiliser ta classe dans ta jsp :
    tu dois tout dabord importer la package
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    <%@page
      language="java"
      import="java.util.*, monProjet.maClasseSql "
    %>
    Ensuite tu peux la manipuler :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    maClasseSql sql = new maClasseSql();
    sql.init();
    sql.setSql("Select * From truc");
    Etc ...

    Par contre tu utilise des taglib donc je suis pas sur que la méthode que je te présente te convienne.
    Mais tu peux déjà essayer un truc comme cà pour etre sur que tu accède bien à tes données, une fois fait, tu peux te pencher sur les taglib ou d'autres manière de les traiter.
    " Je préfère comprendre les gens qui ne me comprennent pas "

  11. #11
    Membre du Club
    Profil pro
    Inscrit en
    Avril 2006
    Messages
    116
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2006
    Messages : 116
    Points : 63
    Points
    63
    Par défaut
    merci de votre aide, mais je dois avouer qu'après avoir construit des sites web avec ColdFusion, ASP, ASP.NEt,php j'y perds vraiment mon latin

    Alors je tente une question, faut croire que je suis un peu con, existe-il un exemple simple de site web faisant appel à une B2D (mysql, sqlserver ou autre) ? Simple du style afficher un tableau avec quelques enregistrements issus de la b2d ...

    Désolé de mon incompréhension

  12. #12
    Membre confirmé Avatar de Jabbal'H
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Octobre 2004
    Messages
    403
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2004
    Messages : 403
    Points : 580
    Points
    580
    Par défaut
    Alors essaye cà, par contre c'est pas dans une jsp, mais c'est exactement la meme chose, là c'est dans une servlet.

    euh ca fait longtemps que je l'ai pas testé, mais bon en théorie ca marche.

    Voici déjà la classe sql ( elle est pas tres propre tout comme le reste c'etait des test et j'ai que cà sous la main )
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
     
    package commun;
     
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    import java.util.Hashtable;
     
     
    public class SqlConnection {
     
    	private String driver = "macromedia.jdbc.sqlserver.SQLServerDriver";
    	private String url = "jdbc:macromedia:sqlserver://localhost:1433;"
    						+ "user=***;password=***;DatabaseName=xxxx";
    	private Connection cnx = null;
    	private Statement st=null;
     
    	public void init(){
     
    		try {			
    			Class.forName(driver);
    			cnx = DriverManager.getConnection(url);		
    			st = cnx.createStatement();						
    		}
    		catch (SQLException ex) {
    			System.out.println("init : " + ex.getMessage().toString());
    		}
    		catch (ClassNotFoundException ex) {
    			System.out.println("init : " + ex.getMessage().toString());
    		}			
    	}
     
    	public void sqlClose(){
    		try {
    			this.cnx.close();
    		}catch (SQLException ex) {
    			System.out.println("init : " + ex.getMessage().toString());
    		}		
    	}
     
    	private String requete="";
    	public void appendLn(String rq){
    		this.requete += " " + rq;		
    	}
     
    	public String getRq() {
    		return this.requete;
    	}
     
    	private Hashtable ht=null;
    	public ResultSet exeSelect() {
    		ResultSet rs = null;
    		try {
    			int i=0;					
    			rs = st.executeQuery(this.requete);			
    			while (rs.next()) {
    				i++;				
    				ht.put(rs.getRef(i),rs.getString(i));				
    			}		
    		}catch (SQLException ex) {
    			System.out.println("exeSelect : " + ex.getMessage().toString());
    		}				
    		return rs;
    	}		
    }
    Déjà mieux vaut utiliser un StringBuffer pour stocker la requete mais bon

    Ensuite voici le code de la servlet :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    import commun.SqlConnection;
    import com.sun.ejb.sqlgen.SQLTypeMapper;
    import java.util.Enumeration;
    import java.util.Hashtable;
    import java.sql.*;
     
    public class ServletPrincip extends HttpServlet{
     
    	protected void doGet(HttpServletRequest request,HttpServletResponse response)
    		throws ServletException,IOException {
     
    		PrintWriter out = response.getWriter();
    		response.setContentType("text/html");
    		SqlConnection sql = new SqlConnection();
    		//Connection cnx = null;
    		ResultSet rs = null;
    		Statement st = null;
    		Hashtable ht=null;
     
    		try {						
    			sql.init();						
    			sql.appendLn("select nomCli from client");
    			out.println(sql.getRq()+"<br>");
    			String cli = "";
     
    			int i=0;
    			rs = sql.exeSelect();
     
     
    			while (rs.next()) {	
     
    				out.println("<br/> RS.getString : " + rs.getString("nomCli"));								
    			}						
     
    			out.println("<br/>TEST FIN");
    			sql.sqlClose();
    		}
    			catch (Exception e) {
    			out.println("ServletPrincip : " +e.getMessage().toString());
    			}				
    	}					
    	}
    Voilà logiquement ca marche, par contre ne relisant cà, c'est vraiment pas propre, y a plein de truc de pas détruit, à utiliser que pour test, mais le principe est là.

    Voilà bon courage
    " Je préfère comprendre les gens qui ne me comprennent pas "

  13. #13
    Membre du Club
    Profil pro
    Inscrit en
    Avril 2006
    Messages
    116
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2006
    Messages : 116
    Points : 63
    Points
    63
    Par défaut
    Merci beaucoup ca fonctionne

    Je m'y remets de suite

  14. #14
    Membre du Club
    Profil pro
    Inscrit en
    Avril 2006
    Messages
    116
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2006
    Messages : 116
    Points : 63
    Points
    63
    Par défaut
    bon j'ai trop vite parler, avec les servlets c'est ok mais pas avec les jsp

    Voici mon code :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
     
    <%@page pageEncoding="UTF-8"%>
    <%@page import="java.sql.*"%>
     
    <%--
    The taglib directive below imports the JSTL library. If you uncomment it,
    you must also add the JSTL library to the project. The Add Library... action
    on Libraries node in Projects view can be used to add the JSTL 1.1 library.
    --%>
     
       <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
        <%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>
     
     
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">
     
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>JSP Page</title>
        </head>
        <body>
     
        <sql:setDataSource var="datasource"
    	url="jdbc:sqlserver://hostname:1433;user=**;password=*****;DatabaseName=jstTest"
            driver="com.microsoft.sqlserver.jdbc.SQLServerDriver" user="**" password="****" />
     
             <sql:query var="queryresults" dataSource="${datasource}">
    	SELECT * FROM test1 
        </sql:query>
     
            <table border=1>
          <tr>
    	 <th>First</th><th>Last</th>
          </tr>
          <c:forEach var="row" items="${queryresults.rows}">
    	 <tr>
    	     <td><c:out value="${row.prenom}" /></td>
    	     <td><c:out value="${row.nom}" /></td>
    	 </tr>
          </c:forEach>
        </table>
     
        </body>
    </html>
    J'ai le message d'erreur suivant :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
     
    Sun Java System Application Server Platform Edition 9.0
     
    type Rapport d'exception
     
    message 
     
    description Le serveur a rencontré une erreur interne () qui l'a empêché de satisfaire la requête.
     
    exception 
     
    javax.servlet.ServletException: javax.servlet.jsp.JspException: Unable to get connection, DataSource invalid: "java.sql.SQLException: No suitable driver"
    	org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:930)
    	org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:863)
    	org.apache.jsp.index_jsp._jspService(index_jsp.java:118)
    	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
    	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:353)
    	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:409)
    	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:317)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
    	com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:73)
    	com.sun.enterprise.web.VirtualServerPipeline.invoke(VirtualServerPipeline.java:120)
    	org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:231)
    	com.sun.enterprise.web.connector.grizzly.ProcessorTask.invokeAdapter(ProcessorTask.java:667)
    	com.sun.enterprise.web.connector.grizzly.ProcessorTask.processNonBlocked(ProcessorTask.java:574)
    	com.sun.enterprise.web.connector.grizzly.ProcessorTask.process(ProcessorTask.java:844)
    	com.sun.enterprise.web.connector.grizzly.ReadTask.executeProcessorTask(ReadTask.java:287)
    	com.sun.enterprise.web.connector.grizzly.ReadTask.doTask(ReadTask.java:212)
    	com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:252)
    	com.sun.enterprise.web.connector.grizzly.WorkerThread.run(WorkerThread.java:75)
     
     
    cause mère 
     
    javax.servlet.jsp.JspException: Unable to get connection, DataSource invalid: "java.sql.SQLException: No suitable driver"
    	org.apache.taglibs.standard.tag.common.sql.QueryTagSupport.getConnection(QueryTagSupport.java:285)
    	org.apache.taglibs.standard.tag.common.sql.QueryTagSupport.doStartTag(QueryTagSupport.java:168)
    	org.apache.jsp.index_jsp._jspx_meth_sql_query_0(index_jsp.java:159)
    	org.apache.jsp.index_jsp._jspService(index_jsp.java:97)
    	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
    	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:353)
    	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:409)
    	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:317)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
    	com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:73)
    	com.sun.enterprise.web.VirtualServerPipeline.invoke(VirtualServerPipeline.java:120)
    	org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:231)
    	com.sun.enterprise.web.connector.grizzly.ProcessorTask.invokeAdapter(ProcessorTask.java:667)
    	com.sun.enterprise.web.connector.grizzly.ProcessorTask.processNonBlocked(ProcessorTask.java:574)
    	com.sun.enterprise.web.connector.grizzly.ProcessorTask.process(ProcessorTask.java:844)
    	com.sun.enterprise.web.connector.grizzly.ReadTask.executeProcessorTask(ReadTask.java:287)
    	com.sun.enterprise.web.connector.grizzly.ReadTask.doTask(ReadTask.java:212)
    	com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:252)
    	com.sun.enterprise.web.connector.grizzly.WorkerThread.run(WorkerThread.java:75)
    pourtant dans netbeans j'ai ajouté dans les libraries : sqljdbc.jar

  15. #15
    Membre confirmé Avatar de Jabbal'H
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Octobre 2004
    Messages
    403
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Octobre 2004
    Messages : 403
    Points : 580
    Points
    580
    Par défaut
    y a un truc qui me choque quand meme, c'est de mettre dans la jsp tous les pramettre de connection, mot de passe, drivers, etc ...
    Je dois que je n'ais jamais utilisé les taglib donc je sais pas si c'est normal.

    Mais est ce que tu as essaye de taper juste le code dans la jsp sans les tag, donc en gros

    " Je préfère comprendre les gens qui ne me comprennent pas "

  16. #16
    Membre averti
    Avatar de dtavan
    Profil pro
    Inscrit en
    Juin 2002
    Messages
    162
    Détails du profil
    Informations personnelles :
    Âge : 54
    Localisation : France

    Informations forums :
    Inscription : Juin 2002
    Messages : 162
    Points : 381
    Points
    381
    Par défaut
    je ne vais pas pouvoir t'aider sur ce coup, mais à mon avis sur sun application server cherche où déclarer ceci :

    dans l'exemple que je t'ai donné .
    David Tavan

    Mon blog 1
    Mon blog 2

  17. #17
    Membre averti
    Avatar de dtavan
    Profil pro
    Inscrit en
    Juin 2002
    Messages
    162
    Détails du profil
    Informations personnelles :
    Âge : 54
    Localisation : France

    Informations forums :
    Inscription : Juin 2002
    Messages : 162
    Points : 381
    Points
    381
    Par défaut
    voici un exemple qui fonctionne

    j'espère que c'est ce que tu cherches

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
     
    <%@page contentType="text/html"%>
    <%@page pageEncoding="UTF-8" import="java.sql.*"%>
    <%--
    The taglib directive below imports the JSTL library. If you uncomment it,
    you must also add the JSTL library to the project. The Add Library... action
    on Libraries node in Projects view can be used to add the JSTL 1.1 library.
    --%>
     
    <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 
    <%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
     
     
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">
     
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>JSP Page</title>
        </head>
        <body>
     
        <h1>JSP Page</h1>
     
            <h1>With sun java server</h1><br/>
     
            <sql:setDataSource var="datasource"
            url="jdbc:sqlserver://localhost:1433,user=*****,password=******,DatabaseName=jspTest"
            driver="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
     
            <sql:query var="queryresults" dataSource="${datasource}">
                    SELECT * FROM test1 
            </sql:query>
     
            <table border=1>
            <tr>
            <th>First</th><th>Last</th>
            </tr>
            <c:forEach var="row" items="${queryresults.rows}">
            <tr>
            <td><c:out value="${row.prenom}" /></td>
            <td><c:out value="${row.nom}" /></td>
            </tr>
            </c:forEach>
            </table>
     
        </body>
    </html>
    David Tavan

    Mon blog 1
    Mon blog 2

  18. #18
    Membre du Club
    Profil pro
    Inscrit en
    Avril 2006
    Messages
    116
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2006
    Messages : 116
    Points : 63
    Points
    63
    Par défaut
    Merci tu me sauve

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. C# et WPF : comment afficher des données dans une DataGrid (to bind or not to bind ?!?)
    Par jmnicolas dans le forum Windows Presentation Foundation
    Réponses: 8
    Dernier message: 31/05/2010, 15h03
  2. [ Debutant ] Comment afficher une image dans une page JSP ?
    Par Hello_World dans le forum Servlets/JSP
    Réponses: 1
    Dernier message: 27/07/2009, 09h13
  3. Réponses: 6
    Dernier message: 11/07/2006, 16h09
  4. [SQL server] Comment Fusionner des données dans une requête
    Par MoTUmBo dans le forum MS SQL Server
    Réponses: 2
    Dernier message: 27/07/2005, 15h24

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo