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
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
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.par contre je n'ai pas trouvé pour SQL Server
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>![]()
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
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>
j'ai essayé ceci :
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
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>
J'ai vraiment besoin d'aide sur ce coup
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.0Merci
Il ne trouve pas les drivers de ton server SQL apparement.
Si tu veux j'utilise cà, mais c'est codé dans une classe :
Par contre c'est lié à un server jrun
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()); } }
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 ?
Partager