fanxin

 

frequenzDB.jsp 可以往数据库中存 还是存在问题。在区分空字符窜何NULL的时候

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page import = "java.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.lang.*" %>
<%@ page import="de.tum.sep.*" %>

<%@ page contentType="text/html; charset=UTF-8" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
<title>FrequenzDB</title>
</head>
<body bgcolor="#DDDDDD">
<%    
     String anzahlFrequenz = (String)request.getParameter("anzahlFrequenzStr");    
     int countFre = Integer.parseInt(anzahlFrequenz, 10);
     out.println("countFre ="+countFre);  
     for (int i = 1, j = 1; i <= countFre; ++i)
     {         
       String frequenz = request.getParameter("frequenz" + i);
       String land = request.getParameter("land" + i);
       String frequenzVon = request.getParameter("frequenzVon" + i);
       String frequenzBis = request.getParameter("frequenzBis" + i);
       String kanalabstand = request.getParameter("kanalabstand" + i);
       
       if (frequenz == null ) frequenz = "";
       if (land == null ) land = "";
       if (frequenzVon == null) frequenzVon = "";
       if (frequenzBis == null ) frequenzBis = "";
       if (kanalabstand == null ) kanalabstand = "";

/*       float f   = Float.parseFloat(frequenz);
       float f_v = Float.parseFloat(frequenzVon);
       float f_b = Float.parseFloat(frequenzBis);
*/
       RandomGUID my_fre_guid = new RandomGUID();
       String fre_guid = my_fre_guid.toString();        
%>
<table width="600" border="0">
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>
<table>
   <tr><font color="#0000FF">FrequenzBereich<%//= i%>:</font></tr>
</table>
<%
    String einheitFre = (String)request.getParameter("einheitFre"+j+"_"+i);
    String einheitFreVon = (String)request.getParameter("einheitFreVon"+j+"_"+i);
    String einheitFreBis = (String)request.getParameter("einheitFreBis"+j+"_"+i);
//Einheit von Frequenz ##########################################################
    String fre1 = new String();
    String fre2 = new String();
    String fre3 = new String();
    String fre4 = new String();

    String einheit_f = new String();
//Einheit von FrequenzVon ######################################################
    String freVon1 = new String();
    String freVon2 = new String();
    String freVon3 = new String();
    String freVon4 = new String();

    String einheit_f_von = new String();
//Einheit von FrequenzBis ###########################################
    String freBis1 = new String();
    String freBis2 = new String();
    String freBis3 = new String();
    String freBis4 = new String();
    
    String einheit_f_bis = new String();     
%>
<table width="600" border="0">
  <tr>
    <td width="124">Frequenz: </td>
    <td width="147"><%= frequenz%></td>
<%
    int f, f_v, f_b;
    f = Integer.parseInt(frequenz,10);
    if (einheitFre == null)
    {
     }
     else if(einheitFre.equals("Hz"))
     {
        fre1 = "selected";
        einheit_f = "Hz";
        f = f;    
     }
     else if(einheitFre.equals("kHz"))
     {
        fre2 = "selected";
        einheit_f = "kHz";    
        f = f * 1000;
     }
     else if(einheitFre.equals("mHz"))
     {
        fre3 = "selected";
        einheit_f = "mHz";    
        f = f * 1000000;
    }
    else if(einheitFre.equals("GHz"))
    {
        fre4 = "selected";
        einheit_f = "GHz";    
        float f_float = f;
        f_float = f_float * 1000000 *1000;
        out.println("f_float =" + f_float);
    }
%>                
    <td><input type="hidden" name = "f" value="<%= f%>"/></td>
    <td width="420"><%= einheit_f%></td>
  </tr>
  <tr>
    <td width="124"> Land: </td>
    <td width="147"><%= land%></td>
    <td width="312">&nbsp;</td>
  </tr>
  <tr>
    <td width="124"> FrequenzVon: </td>
    <td width="147"><%= frequenzVon%></td>
<%
    if( frequenzVon == "")
    {
      f_v = f;
      einheit_f_von = einheit_f;
    }
    else
    {
     f_v = Integer.parseInt(frequenzVon,10);
    if (einheitFreVon == null)
    {
    }
    else if(einheitFreVon.equals("Hz"))
    {
        freVon1 = "selected";  
        einheit_f_von = "Hz";
        f_v = f_v;     
    }
    else if(einheitFreVon.equals("kHz"))
    {
        freVon2 = "selected";
        einheit_f_von = "kHz";
        f_v = f_v * 1000;
    }
    else if(einheitFreVon.equals("mHz"))
    {
        freVon3 = "selected";
        einheit_f_von = "mHz";
        f_v = f_v * 1000000;
    }
    else if(einheitFreVon.equals("GHz"))
    {
        freVon4 = "selected";
        einheit_f_von = "GHz";
        float f_v_float = f_v;
        f_v_float = f_v_float * 1000000 *1000;
        out.println("f_v_float =" + f_v_float);
//        f_v = f_v * 1000000 * 1000;
    }    
   }
%>
    <td><input type="hidden" name = "f_v" value="<%= f_v%>"/></td>        
    <td width="420"><%= einheit_f_von%></td>    
    <td width="312">&nbsp;</td>
  </tr>
  <tr>
    <td width="124"> FrequenzBis: </td>
    <td width="147"><%= frequenzBis%></td>
<%
    if(frequenzBis == "")
    {
      f_b = f;
      einheit_f_bis = einheit_f;
    }
    else
    {
     f_b = Integer.parseInt(frequenzBis,10);
    if (einheitFreBis == null)
    {
    }else if(einheitFreBis.equals("Hz"))
    {
        freBis1 = "selected";
        einheit_f_bis = "Hz";
        f_b = f_b;
    }
    else if(einheitFreBis.equals("kHz"))
    {
        freBis2 = "selected";
        einheit_f_bis = "kHz";
        f_b = f_b * 1000;
    }
    else if(einheitFreBis.equals("mHz"))
    {
        freBis3 = "selected";
        einheit_f_bis = "mHz";
        f_b = f_b * 1000000;
    }
    else if(einheitFreBis.equals("GHz"))
    {
        freBis4 = "selected";
        einheit_f_bis = "GHz";
        float f_b_float = f_b;
        f_b_float = f_b_float * 1000000 *1000;
        out.println("f_b_float =" + f_b_float);
//        f_b = f_b * 1000000 * 1000;
    }
   }    
%>    
    <td><input type="hidden" name = "f_b" value="<%= f_b%>"/></td>
    <td width="420"><%= einheit_f_bis%></td>    
    <td width="312">&nbsp;</td>
  </tr>
  <tr>
    <td width="124">Kanalabstand: </td>
    <td width="147"><%= kanalabstand%></td>
    <td width="312">&nbsp;</td>
  </tr>
</table>       
<%
       out.println("f = "+f);
       out.println("f_v = "+f_v);
       out.println("f_b = "+f_b);  
/*    out.println("f = "+ f);
    out.println("f_v = "+ f_v);
    out.println("f_b = "+ f_b);
*/    
     try {
         Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
         Connection con_fre =java.sql.DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost;1433;databaseName=RFID;","boxer", "boxer");
                          
         Statement st_fre = con_fre.createStatement();
         String  sql_fre = "INSERT INTO Frequenz (FrequenzGUID, Frequenz_in_Hz, Land, FR_BereichVon_Hz, FR_BereichBis_Hz, Kanalabstand_in_Hz)                        VALUES ('"+fre_guid+" ','" +f+ "','"+land+ "','"+f_v+ "','" +f_b+ "','" +kanalabstand + "')";
         st_fre.executeUpdate(sql_fre);
         st_fre.close();
         con_fre.close();
          }catch (ClassNotFoundException e1) {
       //JDBC driver class not found, print error message to the console
           out.println(e1.toString());
           }
           catch (SQLException e2) {
          // Exception when executing java.sql related commands, print error message to the console
           out.println(e2.toString());
             //out.println("Es gibt ein Ueberschreit der String");
           }
           catch (Exception e3) {
          // other unexpected exception, print error message to the console
           out.println(e3.toString());
           }
%>
<%              
   j++;
  }
%>
<table width="600" border="0">
        <tr>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
      </table>
 <table width="400">
   <tr>    
   <td width="300"><input type="submit" name="zurueck" value="Zur&uuml;cken" onclick="self.location.href='frequenz.jsp'" width="" maxlength="40" /></td>
   </tr>
  </table>          
</body>
</html>

posted on 2006-02-15 08:25 fanxin 阅读(149) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航:
 

导航

统计

留言簿

文章档案

Java

matrix

weiqin

中国JSP技术网站

搜索

最新评论