Nome database: reddito Elenco programmi

Nome database: reddito
CAMPO
TIPO
codice
cognome
reddito
int
varchar(20)
float
PRIMARY KEY
Elenco programmi
-
menu.html
menuhref.html
conn_db.jsp
delete.html
delete.jsp
insert.html
insert.jsp
update.html
update.jsp
sel_codice01.html
sel_codice01.jsp
sel_codice02.html
sel_codice02.jsp
sel_cognome.html
sel_cognome.jsp
sel_reddito01.html
sel_reddito01.jsp
sel_reddito02.html
sel_reddito02.jsp
menu' gestione database
esempio di menu' con HREF
connessione a database
delete
insert
update
select codice =
select codice >=
select cognome =
select reddito =
select reddito >=
<! menu.html >
<script type="text/javascript">
function OnSubmitForm()
{
if(document.myform.operation[0].checked == true)
document.myform.action ="insert.html";
if(document.myform.operation[1].checked == true)
document.myform.action ="update.html";
if(document.myform.operation[2].checked == true)
document.myform.action ="delete.html";
if(document.myform.operation[3].checked == true)
document.myform.action ="sel_codice01.html";
if(document.myform.operation[4].checked == true)
document.myform.action ="sel_codice02.html";
if(document.myform.operation[5].checked == true)
document.myform.action ="sel_cognome.html";
if(document.myform.operation[6].checked == true)
document.myform.action ="sel_reddito01.html";
if(document.myform.operation[7].checked == true)
document.myform.action ="sel_reddito02.html";
return true;
}
</script>
<form name="myform" onsubmit="return OnSubmitForm();">
<input type="radio" name="operation" value="1" checked>Inserimento <br>
<input type="radio" name="operation" value="2">Aggiornamento <br>
<input type="radio" name="operation" value="3">Cancellazione <br>
<input type="radio" name="operation" value="4">Selezione per codice = <br>
<input type="radio" name="operation" value="5">Selezione per codice >= <br>
<input type="radio" name="operation" value="6">Selezione per cognome <br>
<input type="radio" name="operation" value="7">Selezione per reddito = <br>
<input type="radio" name="operation" value="8">Selezione per reddito >= <br>
<br>
<p>
<input type="submit" name="submit" value="scelta">
</p>
</form>
<! menuhref.html >
<HTML>
<HEAD>
<TITLE>
MENU HREF
</TITLE>
</HEAD>
<BODY>
<A
<A
<A
<A
<A
<A
<A
<A
HREF="insert.html">Inserimento</A> <br>
HREF="update.html">Aggiornamento</A> <br>
HREF="delete.html">Cancellazione</A> <br>
HREF="sel_codice01.html">Selezione per codice =</A> <br>
HREF="sel_codice02.html">Selezione per codice >=</A> <br>
HREF="sel_cognome.html">Selezione per cognome</A> <br>
HREF="sel_reddito01.html">Selezione per reddito =</A> <br>
HREF="sel_reddito01.html">Selezione per reddito >=</A> <br>
</BODY>
</HTML>
<! conn_db.jsp
connessione a database>
<html>
<%@ page language="java" import="java.io.*,java.util.*,java.sql.*" %>
<body>
<%
String host = "dblabs.fauser.edu";
String dbName = "xxxx";
int port = 3306;
String mysqlURL = "jdbc:mysql://" + host + ":" + port + "/" + dbName;
String username = "xxxx";
String password = "xxxxxxxx";
Connection connection = DriverManager.getConnection(mysqlURL, username,
password);
Statement statement = connection.createStatement();
%>
</body>
</html>
<! insert.html >
<html>
<head>
<title>Inserimento</title>
</head>
<body>
<form action="insert.jsp" method="get">
<table border=1>
<tr><td>CODICE</td><td><input name="f_codice" type="text"></td></tr>
<tr><td>COGNOME</td><td><input name="f_cognome" type="text"></td></tr>
<tr><td>REDDITO</td><td><input name="f_reddito" type="text"></td></tr> <br>
</table>
<br>
<input value="invia" type="submit"><input name="reset" type="reset">
</form>
<A HREF="menu.html">Ritorno a MENU'</A> <br>
</body>
</html>
<! insert.jsp >
<html>
<head>
<title>Inserimento</title>
</head>
<%@ page language="java" import="java.io.*,java.util.*,java.sql.*" %>
<%@ include file="conn_db.jsp" %>
<body>
<%
int codice = Integer.parseInt(request.getParameter("f_codice"));
String cognome = request.getParameter("f_cognome");
float reddito = Float.valueOf(request.getParameter("f_reddito")).floatValue();
int esito=0, nrec=0;
String query = "SELECT * FROM reddito where codice="+codice;
ResultSet resultSet = statement.executeQuery(query);
while(resultSet.next())
nrec++;
if ( nrec > 0 )
out.println("Codice gia' presente nel database");
else
{
String stringa_sql="INSERT into reddito (codice,cognome,reddito) values
("+codice+",'"+cognome+"',"+reddito+")";
esito = statement.executeUpdate(stringa_sql);
if (esito == 1)
out.println("Inserimento eseguito correttamente");
else
out.println("Inserimento non eseguito");
}
resultSet.close();
connection.close();
%>
</body>
<br> <br>
<A HREF="insert.html">Continua</A> <br>
</html>
<! update.html >
<html>
<head>
<title>Aggiornamento</title>
</head>
<body>
<form action="update.jsp" method="get">
<table border=1>
<tr><td>CODICE</td><td><input name="f_codice" type="text"></td></tr>
<tr><td>COGNOME</td><td><input name="f_cognome" type="text"></td></tr>
<tr><td>REDDITO</td><td><input name="f_reddito" type="text"></td></tr> <br>
</table>
<br>
<input value="invia" type="submit">
<input name="reset" type="reset">
<br>
</form>
<A HREF="menu.html">Ritorno a MENU'</A> <br>
</body>
</html>
<! update.jsp >
<html>
<head>
<title>Aggiornamento</title>
</head>
<%@ page language="java" import="java.io.*,java.util.*,java.sql.*" %>
<%@ include file="conn_db.jsp" %>
<body>
<%
int codice = Integer.parseInt(request.getParameter("f_codice"));
String cognome = request.getParameter("f_cognome");
float reddito = Float.valueOf(request.getParameter("f_reddito")).floatValue();
int esito=0, nrec=0;
String query = "SELECT * FROM reddito where codice="+codice;
ResultSet resultSet = statement.executeQuery(query);
while(resultSet.next())
nrec++;
if ( nrec == 0 )
out.println("Codice non presente nel database");
else
{
String stringa_sql="UPDATE reddito SET
cognome='"+cognome+"',reddito="+reddito+" WHERE codice="+codice+"";
esito = statement.executeUpdate(stringa_sql);
if (esito == 1)
out.println("Aggiornamento eseguito correttamente");
else
out.println("Aggiornamento non eseguito");
}
resultSet.close();
connection.close();
%>
</body>
<br><br>
<A HREF="update.html">Continua</A> <br>
</html>
<! delete.html >
<html>
<head>
<title>Cancellazione</title>
</head>
<body>
<form action="delete.jsp" method="get">
<table border=1>
<tr><td>CODICE</td><td><input name="f_codice" type="text"></td></tr> <br>
</table>
<br>
<input value="invia" type="submit">
<input name="reset" type="reset">
</form>
<A HREF="menu.html">Ritorno a MENU'</A> <br>
</body>
</html>
<! delete.jsp >
<html>
<head>
<title>Cancellazione</title>
</head>
<%@ page language="java" import="java.io.*,java.util.*,java.sql.*" %>
<%@ include file="conn_db.jsp" %>
<body>
<%
float codice = Float.valueOf(request.getParameter("f_codice")).floatValue();
String query = "SELECT * FROM reddito where codice="+codice;
ResultSet resultSet = statement.executeQuery(query);
int nrec=0, esito=0;
%>
<table border=1>
<tr><td>CODICE</td><td>COGNOME</td><td>REDDITO</td></tr>
<%
while(resultSet.next())
{
out.println("<tr><td>"+resultSet.getInt(1) + "</td><td>" +
resultSet.getString(2) + "</td><td>" + resultSet.getFloat(3)+"</td></tr>");
nrec++;
}
%>
<br>
</table>
<%
if (nrec==0)
out.println("Nessun record trovato con codice="+codice);
else
{
String sql_delete = "DELETE FROM reddito where codice="+codice;
esito=statement.executeUpdate(sql_delete);
if ( esito == 1)
out.println("Cancellazione eseguita correttamente");
else
out.println("Cancellazione non eseguita");
}
resultSet.close();
connection.close();
%>
</body>
<br> <br>
<A HREF="delete.html">Continua</A> <br>
</html>
<! sel_codice01.html >
<html>
<head>
<title>Ricerca x codice =</title>
</head>
<body>
<form action="sel_codice01.jsp" method="get">
<table border=1>
<tr><td>CODICE</td><td><input name="f_codice" type="text"></td></tr> <br>
</table>
<br>
<input value="invia" type="submit">
<input name="reset" type="reset">
</form>
<A HREF="menu.html">Ritorno a MENU'</A> <br>
</body>
</html>
<! sel_codice01.jsp >
<html>
<head>
<title>Ricerca x codice =</title>
</head>
<%@ page language="java" import="java.io.*,java.util.*,java.sql.*" %>
<%@ include file="conn_db.jsp" %>
<body>
<%
float codice = Float.valueOf(request.getParameter("f_codice")).floatValue();
String query = "SELECT * FROM reddito where codice="+codice;
ResultSet resultSet = statement.executeQuery(query);
int nrec=0;
%>
<br>
<table border=1>
<tr><td>CODICE</td><td>COGNOME</td><td>REDDITO</td></tr>
<%
while(resultSet.next())
{
out.println("<tr><td>"+resultSet.getInt(1) + "</td><td>" +
resultSet.getString(2) + "</td><td>" + resultSet.getFloat(3)+"</td></tr>");
nrec++;
}
%>
</table>
<%
if (nrec==0)
out.println("Nessun record trovato con codice="+codice);
resultSet.close();
connection.close();
%>
</body>
<br><br>
<A HREF="sel_codice01.html">Continua</A> <br>
</html>
<! sel_codice02.html >
<html>
<head>
<title>Ricerca x codice >=</title>
</head>
<body>
<form action="sel_codice02.jsp" method="get">
<table border=1>
<tr><td>CODICE</td><td><input name="f_codice" type="text"></td></tr> <br>
</table>
<br>
<input value="invia" type="submit">
<input name="reset" type="reset">
</form>
<A HREF="menu.html">Ritorno a MENU'</A> <br>
</body>
</html>
<! sel_codice02.jsp >
<html>
<head>
<title>Ricerca x codice >= </title>
</head>
<%@ page language="java" import="java.io.*,java.util.*,java.sql.*" %>
<%@ include file="conn_db.jsp" %>
<body>
<%
float codice = Float.valueOf(request.getParameter("f_codice")).floatValue();
String query = "SELECT * FROM reddito where codice>="+codice;
ResultSet resultSet = statement.executeQuery(query);
int nrec=0;
%>
<br>
<table border=1>
<tr><td>CODICE</td><td>COGNOME</td><td>REDDITO</td></tr>
<%
while(resultSet.next())
{
out.println("<tr><td>"+resultSet.getInt(1) + "</td><td>" +
resultSet.getString(2) + "</td><td>" + resultSet.getFloat(3)+"</td></tr>");
nrec++;
}
%>
</table>
<%
if (nrec==0)
out.println("Nessun record trovato con codice="+codice);
resultSet.close();
connection.close();
%>
<br><br>
<A HREF="sel_codice02.html">Continua</A> <br>
</body>
</html>
<! sel_cognome.html >
<html>
<head>
<title>Ricerca per cognome</title>
</head>
<body>
<form action="sel_cognome.jsp" method="get">
<table border=1>
<tr><td>COGNOME</td><td><input name="f_cognome" type="text"></td></tr> <br>
</table>
<br>
<input value="invia" type="submit">
<input name="reset" type="reset">
</form>
<A HREF="menu.html">Ritorno a MENU'</A> <br>
</body>
</html>
<! sel_cognome.jsp >
<html>
<head>
<title>Ricerca x cognome</title>
</head>
<%@ page language="java" import="java.io.*,java.util.*,java.sql.*" %>
<%@ include file="conn_db.jsp" %>
<body>
<%
String cognome = request.getParameter("f_cognome");
String query = "SELECT * FROM reddito where cognome='"+cognome+"'";
ResultSet resultSet = statement.executeQuery(query);
int nrec=0;
%>
<br>
<table border=1>
<tr><td>CODICE</td><td>COGNOME</td><td>REDDITO</td></tr>
<%
while(resultSet.next())
{
out.println("<tr><td>"+resultSet.getInt(1) + "</td><td>" +
resultSet.getString(2) + "</td><td>" + resultSet.getFloat(3)+"</td></tr>");
nrec++;
}
%>
</table>
<%
if (nrec==0)
out.println("Nessun record trovato con cognome = "+cognome);
resultSet.close();
connection.close();
%>
</body>
<br><br>
<A HREF="sel_cognome.html">Continua</A> <br>
</html>
<! sel_reddito01.html >
<html>
<head>
<title>Ricerca x reddito =</title>
</head>
<body>
<form action="sel_reddito01.jsp" method="get">
<table border=1>
<tr><td>REDDITO</td><td><input name="f_reddito" type="text"></td></tr> <br>
</table>
<br>
<input value="invia" type="submit">
<input name="reset" type="reset">
</form>
<A HREF="menu.html">Ritorno a MENU'</A> <br>
</body>
</html>
<! sel_reddito01.jsp >
<html>
<head>
<title>Ricerca x reddito =</title>
</head>
<%@ page language="java" import="java.io.*,java.util.*,java.sql.*" %>
<%@ include file="conn_db.jsp" %>
<body>
<%
float reddito = Float.valueOf(request.getParameter("f_reddito")).floatValue();
String query = "SELECT * FROM reddito where reddito="+reddito;
ResultSet resultSet = statement.executeQuery(query);
int nrec=0;
%>
<br>
<table border=1>
<tr><td>CODICE</td><td>COGNOME</td><td>REDDITO</td></tr>
<%
while(resultSet.next())
{
out.println("<tr><td>"+resultSet.getInt(1) + "</td><td>" +
resultSet.getString(2) + "</td><td>" + resultSet.getFloat(3)+"</td></tr>");
nrec++;
}
%>
</table>
<%
if (nrec==0)
out.println("Nessun record trovato con reddito = "+reddito);
resultSet.close();
connection.close();
%>
</body>
<br><br>
<A HREF="sel_reddito01.html">Continua</A> <br>
</html>
<! sel_reddito02.html >
<html>
<head>
<title>Ricerca x reddito >=</title>
</head>
<body>
<form action="sel_reddito02.jsp" method="get">
<table border=1>
<tr><td>REDDITO</td><td><input name="f_reddito" type="text"></td></tr> <br>
</table>
<br>
<input value="invia" type="submit">
<input name="reset" type="reset">
</form>
<A HREF="menu.html">Ritorno a MENU'</A> <br>
</body>
</html>
<! sel_reddito02.jsp >
<html>
<head>
<title>Ricerca x reddito >=</title>
</head>
<%@ page language="java" import="java.io.*,java.util.*,java.sql.*" %>
<%@ include file="conn_db.jsp" %>
<body>
<%
float reddito = Float.valueOf(request.getParameter("f_reddito")).floatValue();
String query = "SELECT * FROM reddito where reddito>="+reddito;
ResultSet resultSet = statement.executeQuery(query);
int nrec=0;
%>
<br>
<table border=1>
<tr><td>CODICE</td><td>COGNOME</td><td>REDDITO</td></tr>
<%
while(resultSet.next())
{
out.println("<tr><td>"+resultSet.getInt(1) + "</td><td>" +
resultSet.getString(2) + "</td><td>" + resultSet.getFloat(3)+"</td></tr>");
nrec++;
}
%>
</table>
<%
if (nrec==0)
out.println("Nessun record trovato con reddito >= "+reddito);
resultSet.close();
connection.close();
%>
</body>
<br><br>
<A HREF="sel_reddito02.html">Continua</A> <br>
</html>