Problème d'Update et D'Insert
Je fais des Updates à partir des requètes SQL sans problème.
Par contre lorsque j'essaie avec le commandes JAVA cela ne fonctionne pas!
Pouvez-vous me dire où se situe mon erreur?
Faire un Update
Code:
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
| <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page import="java.util.*, java.sql.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<% Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:Maconnection");
Statement updStmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
ResultSet updRs = updStmt.executeQuery("SELECT * FROM firsttable WHERE (Nom='Bruno')");
updRs.next();
updRs.updateString(3,"Christophe");
updRs.updateRow();
con.close();
%>
</body>
</html> |
ou
Insérer une ligne
Code:
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
| <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page import="java.util.*, java.sql.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<% Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:Maconnection");
Statement updStmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
ResultSet updRs = updStmt.executeQuery("SELECT * FROM firsttable");
updRs.moveToInsertRow();
updRs.updateInt("Id",15);
updRs.updateString("Nom","Alphonso");
updRs.updateString("Prenom","Fred");
updRs.insertRow();
con.close();
%>
</body>
</html> |
Merci
Dominique