2013年9月8日星期日

jsp two cascading delete the contents of a database table


<%
String userName1 = "sa";
String userPasswd = "111111";
String url = "jdbc: sqlserver :/ / localhost: 1433; databaseName = Data"; < br /> String tableName = "College";
/ / create connection and execute the query operation
Class.forName ("com.microsoft.sqlserver.jdbc.SQLServerDriver")
. newInstance ();
Connection conn = DriverManager.getConnection (url, userName1,
userPasswd);
Statement statement = conn.createStatement ( );
String sql2 = "SELECT distinct college FROM" + tableName;
ResultSet rs = statement.executeQuery (sql2);
%>




select faculties :


select specialty :







< / div>






then go backstage after the show in the second query drop-down box , do1.jsp;

<% @ page language = "java" import = "java.util. * "pageEncoding =" gb2312 "%>
<% @ page import =" java.sql. *, java.io. * "%>
<%
String college = new String (request.getParameter ("college"). trim (). getBytes ("ISO8859_1"), "gb2312");

System.out.println (college);
String userName = "sa";
String userPasswd = "111111";
/ / need to connect database name
String dbName = "Data";
/ / table name
String tableName = "College";
String url ; = "jdbc: sqlserver :/ / localhost: 1433; databaseName = Data";
/ / create connection and execute the query operation
Class.forName ("com.microsoft.sqlserver.jdbc . SQLServerDriver ")
. newInstance ();
Connection conn = DriverManager.getConnection (url, userName,
userPasswd);
Statement statement = conn.createStatement ();
String sql = "SELECT major FROM" + tableName
+ "where college = '"+ college +"' ";
System.out.println (" sql: "+ sql);
ResultSet rs = statement . executeQuery (sql);

/ / get the data result set
response.setContentType ("text / html; charset = UTF-8");
response. setHeader ("Cache-Control", "no-cache");
PrintWriter pout = null;
pout = response.getWriter ();

pout.print ("[");
while (rs.next ())
{
try
{
pout.print ("'" + (rs.getString ("major")) + "',");

pout.print (",");
}
catch (Exception e)
{
e.printStackTrace ();
}
}
pout.print ("0]");
rs.close ();
statement.close ();
conn.close (); < br />
%>

get so much today , and finally engage in out, although there are many codes are not my , hey, are from the internet to find, then carefully change the change , and then two drop-down boxes can be displayed on demand , but the time and today shows a problem , do not show up : change9.jsp

<% @ page language = "java" ; import = "java.util. *" pageEncoding = "gb2312"%>
<% @ page import = "java.sql. *"%> < br /> <% @ include file = "connection.jsp"%>



< br />
<%
ResultSet rs1;
String sqlstr;
String select1 = new String (request.getParameter ("select1" ). trim (). getBytes ("ISO8859_1"), "gb2312");
String select2 = new String (request.getParameter ("select2"). trim (). getBytes (" ISO8859_1 ")," gb2312 ");

System.out.println (select1 + select2); shown here first select taken out , but the second has been undefined < / strong>
Statement pstm;
try
{

/ / [i] here is the operation of the database and then deleted , I will write , do not write / /
out.println ("");
}
catch (Exception e)
{
System.out.println (e);
}
%>

1 条评论:

  1. This car has a strong build and well known for its great safety
    credentials. Until there is more information on standards
    and performance, diesel is the most flexible option and clean
    diesel with biodiesel fuel is even better for the environment.

    0 liter turbocharged diesel engine that is highly fuel efficient
    but is also available in the much less expensive 2010 VW Golf.


    My page 2015 Audi A3 Video

    回复删除