Skip to content
Snippets Groups Projects
Commit 5533ca2c authored by Yannis Devos's avatar Yannis Devos
Browse files

modif connection a la bdd, ajout d'autre DAO

parent bdf22bbb
No related branches found
No related tags found
No related merge requests found
package dao;
import java.sql.Connection;
import java.sql.DriverManager;
public class BDConnection {
private Connection connection;
public BDConnection(){
try{
Class.forName("org.postgresql.Driver");
this.connection = DriverManager.getConnection("jdbc:postgresql://psqlserv/but2", "yannisdevosetu", "moi");
} catch (Exception e) {
e.getStackTrace();
}
}
public Connection getConnection(){
return this.connection;
}
}
package dao;
import dto.User;
import java.sql.*;
public class ThreadDAO {
private Connection con;
public ThreadDAO(){
this.con = new BDConnection().getConnection();
}
// WIP //
// public String getAllUsers(){
// StringBuilder txt = new StringBuilder();
// try{
// Statement stmt = this.con.createStatement();
// ResultSet rs = stmt.executeQuery("SELECT * FROM userAccount;");
//
// while(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();
// }
//
// return txt.toString();
// }
//
// public String getUserById(int id){
// StringBuilder txt = new StringBuilder();
// try{
// PreparedStatement stmt = this.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();
// }
//
// return txt.toString();
// }
//
// public void addUser(User nUser){
// try{
// PreparedStatement stmt = this.con.prepareStatement("INSERT INTO userAccount VALUES (?,?,?)");
// stmt.setInt(1, nUser.getID());
// stmt.setString(2, nUser.getUserName());
// stmt.setString(3, nUser.getPwd());
//
// stmt.executeUpdate();
//
// } catch (SQLException sqle) {
// sqle.getStackTrace();
// }
// }
}
......@@ -9,12 +9,7 @@ public class UserDAO extends HttpServlet{
private Connection con;
public UserDAO(){
try{
Class.forName("org.postgresql.Driver");
this.con = DriverManager.getConnection("jdbc:postgresql://psqlserv/but2", "yannisdevosetu", "moi");
} catch (Exception e) {
e.getStackTrace();
}
this.con = new BDConnection().getConnection();
}
public String getAllUsers(){
......@@ -72,49 +67,3 @@ public class UserDAO extends HttpServlet{
}
}
}
\ No newline at end of file
//{
// 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
package dto;
public class Message {
private int msgID;
private String content;
// Constructor //
public Message(int msgID, String content) {
this.msgID = msgID;
this.content = content;
}
// Getter //
public int getMsgID() {
return msgID;
}
public String getContent() {
return content;
}
// Setter //
public void setMsgID(int msgID) {
this.msgID = msgID;
}
public void setContent(String content) {
this.content = content;
}
}
package dto;
public class MyThread {
private int threadID;
private String threadName;
// Constructor //
public MyThread(int id, String name){
this.threadID = id;
this.threadName = name;
}
// Getter //
public int getThreadID() {
return threadID;
}
public String getThreadName() {
return threadName;
}
// Setter //
public void setThreadID(int threadID) {
this.threadID = threadID;
}
public void setThreadName(String threadName) {
this.threadName = threadName;
}
}
......@@ -6,7 +6,6 @@ public class User {
private String pwd;
// Constructor //
public User(int id, String username, String pwd){
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment