Boolaky Priya
how to display data from mysql table in text box using jsp??
0 Answer(s)      4 years and 6 months ago
Posted in : Java Beginners
<p>hi, i have a written a code to display data from a mysql table into txtboxes..But i am getting the following error...</p>

<p>An error occurred at line: 113 in the jsp file: /Cat1.jsp
The local variable v_RGPC may not have been initialized
110:   </tr>
111:   <tr>
112:     <th scope="row">Reference GPC</th>
113:     <td><input type="text" name="txtRGPC" value=&lt;%out.println(v_RGPC);%>/>
114:       </td>
115:     <th>Numint</th>
116:     <td><input type="text" name="txtNI" value=&lt;%out.println(v_NI);%>/></td></p>

<p>here is my source code</p>

<p>&lt;%@ page import="java.sql.*" %> 
&lt;%@ page import="java.io.*" %> </p>

<p><head>
<link rel="stylesheet" type="text/css" href="cintel.css">
<title>Category1</title>
</head></p>

<p><body>
&lt;%
try {</p>

<p>String connectionURL = "jdbc:mysql://200.0.0.153:3306/snms"; 
Connection connection = null;
ResultSet rs=null;
Statement statement=null;
// Load JBBC driver "com.mysql.jdbc.Driver". 
Class.forName("com.mysql.jdbc.Driver").newInstance(); 
connection = DriverManager.getConnection(connectionURL, "root", "root");
int updateQuery = 0;
String QueryString = "SELECT * FROM code<em>ot WHERE code</em>codeot=12";
//Connection con=null;
int v_TS     = 1;
String v_RGPC; <br />
String v_CETR; <br />
String v_DR; <br />
String v_CS; <br />
String v_CP; <br />
String v_TOp; <br />
String v_Ddeb; <br />
String v_COEIE; <br />
String v_CAtt; <br />
String v_IDAtt; <br />
String v_NI; <br />
String v_UP; <br />
String v_Centre; <br />
String v_CodeO; <br />
String v_CGest; <br />
String v_TEq; <br />
String v_Dfin; <br />
String v_Zone; <br />
String v_CTrx; <br />
String v_NChan; <br />
String v_Code; <br />
String v_QtL; <br />
String v_Large; <br />
String v_Haut; <br />
String v_Des; <br />
String v_Maj; <br />
String v_Qt; <br />
String v_Cout; <br />
String v_Tot;          </p>

<p>// check weather connection is established or not by isClosed() method 
if(!connection.isClosed())
statement = connection.createStatement();</p>

<pre class="prettyprint">      // sql query to retrieve values from the secified table.
      rs = statement.executeQuery(QueryString);
</code></pre>

<p>while(rs.next())
{
v_RGPC   = "rs.getString(2)";
v_CETR   = rs.getString(2);
v_DR     = rs.getString(2);
v_CS     = rs.getString(2);
v_CP     = rs.getString(2);
v_TOp    = rs.getString(2);
v_Ddeb   = rs.getString(2);
v_COEIE  = rs.getString(2);
v_CAtt   = rs.getString(2);
v_IDAtt  = rs.getString(2);
v_NI     = rs.getString(2);
v_UP     = rs.getString(2);
v_Centre = rs.getString(2);
v_CodeO  = rs.getString(2);
v_CGest  = rs.getString(2);
v_TEq    = rs.getString(2);
v_Dfin   = rs.getString(2);
v_Zone   = rs.getString(2);
v_CTrx   = rs.getString(2);
v_NChan  = rs.getString(2);
v_Code   = rs.getString(2);
v_QtL    = rs.getString(2);
v_Large  = rs.getString(2);
v_Haut   = rs.getString(2);
v_Des    = rs.getString(2);
v_Maj    = rs.getString(2);
v_Qt     = rs.getString(2);
v_Cout   = rs.getString(2);
v_Tot    = rs.getString(2);</p>

<p>}</p>

<p>%></p>

<form method="post" action="insertdata.jsp">
<h2>Saisie Attachement</h2>
<table width="1300">
  <tr>
    <th colspan="2" scope="col">Attachement Sur l'OT/L'OEIE: ATT_GDP_01</th>
    <th colspan="3" scope="col">Etat1</th>
    <th colspan="3" scope="col">Flux</th>
  </tr>
  <tr>
    <th width="216" scope="row">Type de Situation</th>
    <td><input type="text" name="txtTS"/></td>
  </tr>
  <tr>
    <th scope="row">Reference GPC</th>
    <td><input type="text" name="txtRGPC" value=<%out.println(v_RGPC);%>/>
      </td>
    <th>Numint</th>
    <td><input type="text" name="txtNI" value=<%out.println(v_NI);%>/></td>
  </tr>
  <tr>
    <th scope="row">Code ETR</th>
    <td><input type="text" name="txtCETR" value=<%out.println(v_CETR);%>/></td>
    <th>Unite de Production</th>
    <td><input type="text" name="txtUP" value=<%out.println(v_UP);%>/></td>
  </tr>
  <tr>
    <th scope="row">Domaine Reseau</th>
    <td><input type="text" name="txtDR" value=<%out.println(v_DR);%>/></td>
    <th>Centre</th>
    <td><input type="text" name="txtCentre" value=<%out.println(v_Centre);%>/></td>
    <th>Zone</th>
    <td><input type="text" name="txtZone" value=<%out.println(v_Zone);%>/></td>
  </tr>
  <tr>
    <th scope="row">Code Secteur</th>
    <td><input type="text" name="txtCS" value=<%out.println(v_CS);%>/></td>
    <th>Code OEIE</th>
    <td><input type="text" name="txtCodeO" value=<%out.println(v_CodeO);%>/></td>
    <th>Famille Cat de Tvx</th>
    <td><input type="text" name="txtCTrx" value=<%out.println(v_CTrx);%>/></td>
    <th>No Chantier</th>
    <td><input type="text" name="txtNChan" value=<%out.println(v_NChan);%>/></td>
  </tr>
  <tr>
    <th scope="row">Code Prometee</th>
    <td><input type="text" name="txtCP" value=<%out.println(v_CP);%>/></td>
    <th>Code de Ch de Gestion</th>
    <td><input type="text" name="txtCGest" value=<%out.println(v_CGest);%>/></td>
  </tr>
  <tr>
    <th scope="row">Type d'Operation</th>
    <td><input type="text" name="txtTOp" value=<%out.println(v_TOp);%>/></td>
    <th>Type d'Equipement</th>
    <td><input type="text" name="txtTEq" value=<%out.println(v_TEq);%>/></td>
  </tr>
  <tr>
    <th scope="row">Date de Debut</th>
    <td><input type="text" name="txtDdeb" value=<%out.println(v_Ddeb);%>/></td>
    <th>Date de Fin</th>
    <td><input type="text" name="txtDfin" value=<%out.println(v_Dfin);%>/></td>
  </tr>
  <tr>
    <th scope="row">Commentaire de l'OEIE</th>
    <td colspan="2"><input type="text" name="txtCOEIE" size="57" value=<%out.println(v_COEIE);%>/></td>
  </tr>
  <tr>
    <th scope="row">Commentaire de l'Attelem</th>
    <td colspan="2"><input type="text" name="txtCAtt" size="57" value=<%out.println(v_CAtt);%>/></td>
  </tr>
  <tr>
    <th scope="row">Indicateur du dernier Attelem</th>
    <td><input type="text" name="txtIDAtt" value=<%out.println(v_IDAtt);%>/></td>
  </tr>
  <tr></tr>
<tr></tr>
</table>
<br>
  <table width="1300">
  <tr>
    <th colspan="8" scope="col">Saisie de Code de travaux et/ou materiels associes</th>
   </tr>
   <tr>

   </tr>
   <tr>
   <th>Code</th>
   <td><input type="text" name="txtCode"/></td>
   <th>Qt/Long</th>
   <td><input type="text" name="txtQtL"/></td>
   <th>Large</th>
   <td><input type="text" name="txtLarge"/></td>
   <th>Haut</th>
   <td><input type="text" name="txtHaut"/></td>
   </tr>
   <tr>
     <td colspan="8" rowspan="2">Lignes ASP et Materiel</td>
   </tr>
</table>
  <br>
  <table width="1300">
  <tr>
    <th colspan="10">Saisie de lignes des factures</th>
   </tr>
    <tr>
     <td colspan="10"> </td>
   </tr>
   <tr>
   <th>Designation</th>
   <td><input type="text" name="txtDes"/></td>
   <th>Maj</th>
   <td><input type="text" name="txtMaj"/></td>
   <th>Qt</th>
   <td><input type="text" name="txtQt"/></td>
   <th>Cout</th>
   <td><input type="text" name="txtCout"/></td>
   <th>Total</th>
   <td><input type="text" name="txtTot"/></td>
   </tr>
   <tr>
     <td colspan="10"> </td>
   </tr>
   <tr>
     <td colspan="3.9"><input type="submit" name="btnsub"></td>
     <td colspan="3.9"> </td>
     <td colspan="4"> </td>
   </tr>
  </table>
</form>

<p>&lt;%connection.close();
}
catch (Exception ex) {
            out.println("Unable to connect to database." + ex);</p>

<pre class="prettyprint">        }
</code></pre>

<p>%>
</body>
</html></p>

<p>Plz help me</p>

<p>Regards priya</p>
Advertisement
View Answers









Related Tutorials/Questions & Answers:
Advertisements