Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Accès à la base de donnees via JSP

1 réponse
Avatar
amach_fatima
Bonjour à tous,

je cherche à accéder à ma base de données sans utiliser les servlets
mais seulement avec jsp.

Test.jsp

<%@ include file="../inclusion/connexion.jsp" %>
<%!
String titre;
String sql;

String artId = request.getParameter("article");

if( artId != null )
{
// modification d article

titre = "Modification de l'article " + artId;

//sql = "SELECT * FROM article WHERE id = " + artId;

}
else
{
// ajout d article

titre = "Ajout d'article";

//sql = "INSERT INTO article (id) VALUES ('artID')" ;

}

%>
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<!-- Date de création: 29/05/2004 -->
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1" />
<title><%= titre %></title>
</head>
<body>

<h1><%= titre %>
</body>
</html>


et connexion.jsp

<%@ page import="java.sql.*,java.io.*,java.util.*" %>
<%!

private static Connexion creerConnexion ()
{
Connexion co;
String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
String dbUrl = "jdbc:odbc:myodbc";
String user = "root";
String password = "olivier";

try {
Class.forName(driver);
co = java.sql.DriverManager.getConnection(dbUrl, user, password);
}
catch (Exception e)
{
co = NULL;
}

return (co);
}

private static void quitterConnexion (Connexion co)
{
co.close();
}

%>

A la compilation, Tomcat ne reconnait l'objet Connexion

Est ce la façon la plus simple à procéder?

1 réponse

Avatar
Jean Bernard Root

Est ce la façon la plus simple à procéder?


C'est à la fois la plus simple et la pire :-/

Peut-être que la taglib dbtags de jakarta vous permettra de faire un peu
moins pire comme conception ?

http://www.onjava.com/pub/a/onjava/2004/05/05/dbtags.html