
please provide the example for fetching values from database into text field of table
as if i am trying following
String query = "select * from LTCINFO.PERSONS";
st1 = con.createStatement();
rs = st1.executeQuery(query);
while(rs.next())
{
out.println("<tr>");
out.println("<td><input type=\"hidden\" name=\"P_ID\" value=\"rs.getString(1)\"></td>");
out.println("<td><input type=\"text\" name=\"LASTNAME\" value=\"rs.getString(2)"></td>");
out.println("<td><input type=\"text\" name=\"FIRSTNAME\"value=\"rs.getString(3)\"></td>");
out.println("<td><input type=\"text\" name=\"ADDRESS\" value=\"rs.getString(4)\"></td>");
the i am getting "rs.getString" in the text field also..

import java.awt.*;
import java.sql.*;
import javax.swing.*;
import java.awt.event.*;
class FormDemo{
public static void main(String[]args){
JFrame f=new JFrame();
JPanel panel;
JLabel label1,label2;
final JTextField text1,text2;
label1 = new JLabel();
label1.setText("Name:");
text1 = new JTextField(20);
label2 = new JLabel();
label2.setText("Address:");
text2 = new JTextField(20);
panel=new JPanel(new GridLayout(2,2));
panel.add(label1);
panel.add(text1);
panel.add(label2);
panel.add(text2);
f.add(panel);
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root", "root");
Statement st=conn.createStatement();
ResultSet rs=st.executeQuery("select * from data where id=1");
while(rs.next()){
text1.setText(rs.getString("name"));
text2.setText(rs.getString("address"));
}
}
catch(Exception e){}
f.pack();
f.setVisible(true);
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.