ashwini koli
display data on text field
1 Answer(s)      4 years and 8 months ago
Posted in : Java Beginners

I have created one table into SQL 8i. table contains 4 number data type columns. I want to retrieve data from that column and display that data on text field.

    String q="select * from Result1 where UserName='"+t1f.getText()+"'";
       rs=st.executeQuery(q);
       if(rs.next())
         {
                    int x=rs.getInt(2); 
                    int y=rs.getInt(3);
                    int p=rs.getInt(4); 
                    int qq=rs.getInt(5);
                    int r=rs.getInt(6); 
                    String s2=new Integer(x).toString();
                    String s3=new Integer(y).toString();
                    String s4=new Integer(p).toString();
                    String s5=new Integer(qq).toString();
                    String s6=new Integer(r).toString();
a22.setText(s2);
a33.setText(s3);
a44.setText(s4);
a55.setText(s5);
a66.setText(s6);

} This is my code for retrieving data from table setting to textfield. This throws exception as

java.sql.SQLException: [Microsoft][ODBC Driver Manager] Invalid cursor state

please give me solution for this as early as possible..

Ads

View Answers

April 17, 2012 at 11:26 AM


Follow these steps:

1)Go to the start>>Control Panel>>Administrative Tools>> data sources.

2)Click Add button and select the driver Microsoft Access Driver(*.mdb).

3)After selecting the driver, click finish button.

4)Then give Data Source Name(DSN) and click ok button.

5)Your DSN will get created.

6)Restart your compiler and compile the given code.

Here our dsn is college.

import java.awt.*;
import java.sql.*;
import javax.swing.*;
import java.awt.event.*;

class Form extends JFrame
{
JButton ADD;
JPanel panel;
JLabel label1,label2;
final JTextField text1,text2;
Form(){
label1 = new JLabel();
label1.setText("Email Id:");
text1 = new JTextField(20);

label2 = new JLabel();
label2.setText("Contact No:");
text2 = new JTextField(20);

ADD=new JButton("Add");

panel=new JPanel(new GridLayout(3,2));
panel.add(label1);
panel.add(text1);
panel.add(label2);
panel.add(text2);
panel.add(ADD);
add(panel);
setTitle("FORM");
ADD.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae){
String value1=text1.getText();
String value2=text2.getText();
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
         Connection conn=DriverManager.getConnection("jdbc:odbc:college");
        Statement st=conn.createStatement();
             st.executeUpdate("insert into data(email,contactNo) values('"+value1+"','"+value2+"')");
            JOptionPane.showMessageDialog(null,"Inserted Successfully!");
        }

catch(Exception e){}
    }
});
}
}
class FormDemo{
public static void main(String arg[]){
try
{
Form frame=new Form();
frame.pack();
frame.setVisible(true);
}
catch(Exception e)
{}
}
}









Related Tutorials/Questions & Answers:
regarding out put display in html text field
regarding out put display in html text field  how to dispaly the output coming from servlet in a particular text field of html
Retrive data from databse to a text field - Java Server Faces Questions
Retrive data from databse to a text field  Hi, Can you give me a source code to rertrve data from Mysql databse to a text field using JSF.....by selecting option from a dropdown option
Advertisements
text field
text field  How to retrieve data from text field   Hi Friend, Try the following code: import java.awt.*; import javax.swing.*; import java.awt.event.*; class RetrieveDataFromTextFields{ public static void main
how to display data from database according to entered value in search field
how to display data from database according to entered value in search... contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE HTML PUBLIC "-//W3C...-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>
converting field to text sql
converting field to text sql  I wanted to convert the field to TEXT in SQL.. is it possible?   SQL - Converting the field to TEXT works... the field to TEXT works SELECT CONVERT(TEXT,fld_name) FROM TABLE_NAME
jsf text field not blank
jsf text field not blank  text field not clear in jsf onclick of reset button in my application initial value not deleted   Hello Friend, Post your code. Thanks
automatically move next page when data fetched from database is stored in text field
automatically move next page when data fetched from database is stored in text field  hi I have php page where i have two text fields . The data are stored in database wherein when the in the first text field the data is already
validate text field iPhone
validate text field iPhone  i got two different UITextfield in my iPhone application for user login. Just wondering how to validate
how to display data from mysql table in text box using jsp??
how to display data from mysql table in text box using jsp??  <p>hi, i have a written a code to display data from a mysql table into txtboxes...="row">Reference GPC</th> 113: <td><input type="text" name
CALULATION IN TEXT FIELD
CALULATION IN TEXT FIELD  Suppose 3 text Field first amount ,second amount and third sum of these amount,this amount will appear when tab in next filed(i don't want use any type button) in java swing HOW? PLEASE HELP
swing text field problem
swing text field problem  I want to navigate the content of text field from one class to another and viceversa through button but when I am getting the text from first class I am getting null value.please help me..here
swing text field problem
swing text field problem  I want to navigate the content of text field from one class to another and viceversa through button but when I am getting the text from first class I am getting null value.please help me..here
iPhone Text Field Validation
data from user. In this tutorial we are going to limiting the text field input... iPhone Text Field Validation In any user based application "...;. We have also take a Text field on the view to take the input from user
Digit Only text field
Digit Only text field  How should we accept digits only in a textbox? (using JSTL only, without Javascript
Show text field & check input using jQuery
will discuss about how to display 'text field' by a button click & check... how to display 'text field' by a button click & check input using...; it will display a text field and a question , if the answer is yes then ,we have
Text field save as word file
Text field save as word file  Dear experts At run how to save set of text field contains text into single Word file. To save in our desktop computer. Solve my problem
clearing text field in spring form
clearing text field in spring form  hi, I have spring form in that i have security question dropdown field and security answer text field ,when i submitted form with errors the answers text field value should be clear, for this i
rich text field - JSP-Servlet
rich text field  Hi, this is jawahar. my question i need rich text field in my program . plz send me the code
iPhone Text Field Border 
Text Field Boarder  In this tutorial will learn about the text field Boarder, we can set the boarder of text field by selecting the text field... for the text field. This project is View Based Application and here will take four text
Use of Text Field
Use of Text Field, Text box, Text Area, Checkbox,Dropdownlist and Radio... types of information. A form contains form elements checkbox, text field, radio button etc.) through which users can input their data. A form is created using
text field validation - Java Beginners
text field validation  hi How to validate allow only decimal number in text box in jsp?  Hi Friend, Try the following code: function isDecimal(str){ if(isNaN(str) || str.indexOf(".")<0){ alert
focus text field - Swing AWT
focus text field  i want to move cursor to next text field by pressing enter.i have created the following coding. but it does nt working.pls help...(); JOptionPane.showMessageDialog(savebutton, "YOUR DATA HAS BEEN SAVED SUCCESSFULLY
focus text field - Swing AWT
focus text field  i want to move cursor to next text field...(); JOptionPane.showMessageDialog(savebutton, "YOUR DATA HAS BEEN SAVED SUCCESSFULLY...(savebutton, "your data has been saved successfully!"); con.close(); } catch
Display data
Display data  after successful login how i can fetch my account information from sql database
Text Field in HTML
Text Field in HTML       The Text Field in HTML are one line areas, which enable the user... Text Field in HTML.In this Tutorial, the code create a text field in HTML page
JSP combo and text field related questio
JSP combo and text field related questio  in JSP,i had stored data from database in a textboxes usin combo..now i want to use these values of text... and name given to that text field..but its showing somethimng null pointer exception
Can i insert image into struts text field
Can i insert image into struts text field  please tell me can i insert image into text field
fetch values from database into text field
fetch values from database into text field  please provide the example for fetching values from database into text field of table wth edit...;/td>"); the i am getting "rs.getString" in the text field also..  
fetch values from database into text field
fetch values from database into text field  please provide the example for fetching values from database into text field of table as if i am... "rs.getString" in the text field also..   import java.awt.*; import
Text Field Midlet Example
Text Field MIDlet Example       This example illustrates how to insert text field in your form... will be run then first of all the startApp() method will called and it display
How to Define Text Field Validation iPhone
How to Define Text Field Validation iPhone  Hi, Can anybody explain me how to define textfield validation iPhone program. please phone online help reference or example. Thanks