Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
S4a021 Web Backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Charlie Darques
S4a021 Web Backend
Commits
fd78a294
Commit
fd78a294
authored
5 months ago
by
Yannis Devos
Browse files
Options
Downloads
Patches
Plain Diff
dao preque fini
parent
9cbfae96
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
dao/UserDAO.java
+92
-36
92 additions, 36 deletions
dao/UserDAO.java
package-lock.json
+6
-0
6 additions, 0 deletions
package-lock.json
with
98 additions
and
36 deletions
dao/UserDAO.java
+
92
−
36
View file @
fd78a294
...
...
@@ -8,47 +8,103 @@ import jakarta.servlet.http.*;
import
jakarta.servlet.annotation.WebServlet
;
@WebServlet
(
"/sae-userDAO"
)
public
class
UserDAO
extends
HttpServlet
private
Connection
con
=
DriverManager
.
getConnection
(
"jdbc:postgresql://psqlserv/but2"
,
"yannisdevosetu"
,
"moi"
)
;
public
class
UserDAO
extends
HttpServlet
{
private
Connection
con
;
{
public
void
service
(
HttpServletRequest
req
,
HttpServletResponse
res
)
throws
ServletException
,
IOException
{
StringBuilder
txt
=
new
StringBuilder
(
"<tr><th>nMatch</th><th>eq1</th><th>eq2</th><th>date</th><th>sc1</th><th>sc2</th></tr>"
);
public
UserDAO
(){
try
{
Class
.
forName
(
"org.postgresql.Driver"
);
this
.
con
=
DriverManager
.
getConnection
(
"jdbc:postgresql://psqlserv/but2"
,
"yannisdevosetu"
,
"moi"
);
}
catch
(
Exception
e
)
{
e
.
getStackTrace
();
}
}
public
String
getAllUsers
(){
StringBuilder
txt
=
new
StringBuilder
();
try
{
Statement
stmt
=
con
.
createStatement
();
ResultSet
rs
=
stmt
.
executeQuery
(
"SELECT * FROM
ren
cont
res
"
);
ResultSet
rs
=
stmt
.
executeQuery
(
"SELECT * FROM
userAc
co
u
nt
;
"
);
while
(
rs
.
next
()){
int
nMatch
=
rs
.
getInt
(
1
);
int
eq1
=
rs
.
getInt
(
2
);
int
eq2
=
rs
.
getInt
(
3
);
String
date
=
rs
.
getString
(
4
);
int
sc1
=
rs
.
getInt
(
5
);
int
sc2
=
rs
.
getInt
(
6
);
int
userId
=
rs
.
getInt
(
1
);
String
username
=
rs
.
getString
(
2
);
String
pwd
=
rs
.
getString
(
3
);
txt
.
append
(
"Id : "
).
append
(
userId
).
append
(
" Username : "
).
append
(
username
).
append
(
" Password : "
).
append
(
pwd
).
append
(
'\n'
);
}
}
catch
(
SQLException
sqle
)
{
sqle
.
getStackTrace
();
}
txt
.
append
(
"<tr><td>"
).
append
(
nMatch
).
append
(
"</td><td>"
).
append
(
eq1
)
.
append
(
"</td><td>"
).
append
(
eq2
)
.
append
(
"</td><td>"
).
append
(
date
)
.
append
(
"</td><td>"
).
append
(
sc1
)
.
append
(
"</td><td>"
).
append
(
sc2
)
.
append
(
"</td></tr>"
);
return
txt
.
toString
();
}
}
catch
(
ClassNotFoundException
cnfe
){
System
.
out
.
println
(
cnfe
.
getMessage
());
public
String
getUserById
(
int
id
){
StringBuilder
txt
=
new
StringBuilder
();
try
{
PreparedStatement
stmt
=
con
.
prepareStatement
(
"SELECT * FROM userAccount WHERE id=?"
);
stmt
.
setInt
(
1
,
id
);
ResultSet
rs
=
stmt
.
executeQuery
();
if
(
rs
.
next
()){
int
userId
=
rs
.
getInt
(
1
);
String
username
=
rs
.
getString
(
2
);
String
pwd
=
rs
.
getString
(
3
);
txt
.
append
(
"Id : "
).
append
(
userId
).
append
(
" Username : "
).
append
(
username
).
append
(
" Password : "
).
append
(
pwd
).
append
(
'\n'
);
}
}
catch
(
SQLException
sqle
)
{
sqle
.
getStackTrace
();
}
res
.
setContentType
(
"text/html;charset=UTF-8"
);
PrintWriter
out
=
res
.
getWriter
();
out
.
println
(
"<head><title>servlet first</title>"
);
out
.
print
(
"<link href=\"css/styles.css\" rel=\"stylesheet\" />"
);
out
.
println
(
"<META content=\"charset=UTF-8\"></head><body><center>"
);
out
.
println
(
"<h1>Test de ma Servlet</h1>"
);
out
.
println
(
"<h2>Super ! ça marche</h2>"
);
out
.
println
(
"<table>"
+
txt
+
"</table>"
);
out
.
println
(
"</center> </body>"
);
return
txt
.
toString
();
}
}
//{
// public void service( HttpServletRequest req, HttpServletResponse res )
// throws ServletException, IOException
// {
// StringBuilder txt = new StringBuilder("<tr><th>nMatch</th><th>eq1</th><th>eq2</th><th>date</th><th>sc1</th><th>sc2</th></tr>");
//
// try {
// Statement stmt = con.createStatement();
// ResultSet rs = stmt.executeQuery("SELECT * FROM rencontres");
//
// while (rs.next()) {
// int nMatch = rs.getInt(1);
// int eq1 = rs.getInt(2);
// int eq2 = rs.getInt(3);
// String date = rs.getString(4);
// int sc1 = rs.getInt(5);
// int sc2 = rs.getInt(6);
//
// txt.append("<tr><td>").append(nMatch).append("</td><td>").append(eq1)
// .append("</td><td>").append(eq2)
// .append("</td><td>").append(date)
// .append("</td><td>").append(sc1)
// .append("</td><td>").append(sc2)
// .append("</td></tr>");
// }
//
// } catch(ClassNotFoundException cnfe){
// System.out.println(cnfe.getMessage());
// }
//
// res.setContentType("text/html;charset=UTF-8");
// PrintWriter out = res.getWriter();
// out.println( "<head><title>servlet first</title>" );
// out.print("<link href=\"css/styles.css\" rel=\"stylesheet\" />");
// out.println( "<META content=\"charset=UTF-8\"></head><body><center>" );
// out.println( "<h1>Test de ma Servlet</h1>" );
// out.println( "<h2>Super ! ça marche</h2>" );
// out.println("<table>" + txt + "</table>");
// out.println( "</center> </body>" );
// }
//}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
package-lock.json
0 → 100644
+
6
−
0
View file @
fd78a294
{
"name"
:
"s4a021-web-backend"
,
"lockfileVersion"
:
3
,
"requires"
:
true
,
"packages"
:
{}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment