Anshuman Ptaew
code for insert button
2 Answer(s)      3 years and 2 months ago
Posted in : Java Beginners

i want code for insert button(in image) . This is to be used for inserting the values in mysql databasesCapture

Advertisement
View Answers

May 9, 2012 at 5:55 PM


The given code uses Swing components to create a image button and allow the user to enter name and address. As the user clicks the image button, the data will get stored into the database.

    import java.sql.*;
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    class  InsertData{
        public static void main(String[] args){
            JFrame f=new JFrame();
            f.setLayout(null);
            JLabel lab1=new JLabel("Name : ");
            JLabel lab2=new JLabel("Address: ");

            final JTextField text=new JTextField(20);
            final JTextArea area=new JTextArea(5,20);
            JScrollPane pane=new JScrollPane(area);
            JButton b=new JButton(new ImageIcon("c:/image1.gif"));

            lab1.setBounds(10,10,100,20);
            text.setBounds(120,10,150,20);

            lab2.setBounds(10,40,100,20);
            area.setBounds(120,40,150,60);

            b.setBounds(120,110,100,20);
            b.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent e){
                    String st1=text.getText();
                    String st2=area.getText();
                 try{
                 Class.forName("com.mysql.jdbc.Driver").newInstance();
                 Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");
                 PreparedStatement pstmt = conn.prepareStatement("insert into data(name,address) values(?,?)");

                 pstmt.setString(1, st1);
                 pstmt.setString(2, st2 );
                 pstmt.executeUpdate();

                 JOptionPane.showMessageDialog(null,"Inserted Successfully!");
                 }
                 catch(Exception ex){}
                }
            });
            f.add(lab1);
            f.add(text);
            f.add(lab2);
            f.add(area);
            f.add(b);
            f.setVisible(true);
            f.setSize(350,200);
        }
    }


December 18, 2012 at 7:25 PM


can u please post the answer using php and javascript.










Related Tutorials/Questions & Answers:
code for insert button
code for insert button    i want code for insert button(in image...;The given code uses Swing components to create a image button and allow the user to enter name and address. As the user clicks the image button, the data will get
insert code jsp to access
insert code jsp to access   insert code jsp to access
Advertisements
insert Images using if condition on a button in NetBeans
insert Images using if condition on a button in NetBeans  I wantted to insert Images using if condition on a button that is performed to change... of the source code please! HELP ME
JSP Radio Button MySQL insert - JSP-Servlet
with the code to store radio button data and checkbox data to MySQL table. For example in the backend table there is only one column for Gender, how do I insert male...JSP Radio Button MySQL insert  Hi, I have an HTML form which has
insert , edit , and delete button in one jsp page
insert , edit , and delete button in one jsp page  hello I want to ask about the way of creating a jsp page contains insert , edit , and delete buttons and manipulate data in database directly. any help please or hints
facebook like button code
facebook like button code  How to create a facebook like button? can anyone share the code..?? Thanks in advance
BROWSE BUTTON CODE
BROWSE BUTTON CODE  HOW TO STORE THE FILE BROWSE TO THE DATABASE   JSP File Upload 1)page.jsp: <%@ page language="java" %> <... = connection.prepareStatement("insert into file(file_data) values(?)"); fis = new FileInputStream(f
BROWSE BUTTON CODE
BROWSE BUTTON CODE  HOW TO STORE THE FILE BROWSE TO THE DATABASE   JSP File Upload 1)page.jsp: <%@ page language="java" %> <... = connection.prepareStatement("insert into file(file_data) values(?)"); fis = new FileInputStream(f
code to disable back button of browser
code to disable back button of browser  code to disable back button of browser
code to disable back button of browser
code to disable back button of browser  code to disable back button of browser
insert code using spring - Spring
insert code using spring  Hi, Can any one send code for inserting the data in database using spring and hibernate .. Many thanks, Raghavendra  Hi Friend, Please visit the following link: http
help in insert code - JSP-Servlet
help in insert code  I have some doubt in following code. I want to insert value using prepared statement.we r accessing connection from other...;insert regiform values('"+firstname+"','"+address+"','"
code for insert the value from jsp to access database
code for insert the value from jsp to access database  code for insert the value from jsp to access database
java code to insert select at run time....????
java code to insert select at run time....????  java database code to retrieve data at runtime and please give codes for insert delete too.... using...;td><%=rs.getString(5)%></td> <td><input type="button
Code to insert date in to database - Development process
Code to insert date in to database  Hi , in my following code i want... getting error . plz send me code Error 500--Internal Server Error...:170)   Hi Friend, Try the following code: Thanks
how to insert, retrieve data from,to db(code)....
how to insert, retrieve data from,to db(code)....  Hi..... i ve... db. cn u plz tel me the code in detail.n i thk it shud b written in jdbc.....i ve written sum code,bt gting so many doubts in that....so plzzzz help
how to insert, retrieve data from,to db(code)....
how to insert, retrieve data from,to db(code)....  Hi, i have created... plz tel me the code in detail.n i thk it shud b written in jdbc.....i ve written sum code,bt gting so many doubts in that....so plzzzz help me by giving some
insert
insert  insert data in database from servlet through JDBC   Ho Friend, Please visit the following: Insert data into database Thanks
Insert a row in 'Mysql' table using JSP Code
Insert a row in 'Mysql' table using JSP Code In this section, we will discuss about how to insert data in Mysql database using JSP code. Query...; Mysql database Table. Code to insert row in Mysql table : databaseinsertion.jsp
Submit comments in database when user clicks on submit button
Submit comments in database when user clicks on submit button       This is detailed java code to show how to submit comments from a jsp page and insert it to the MySql
Button
Button  How to use image for button in JSF
in the below code two errors are there one at the button onclick atttibute and the next is at the next button
in the below code two errors are there one at the button onclick atttibute and the next is at the next button  <%@ page import="java.sql.*" %> function editRecord(id){ var f=document.form; f.method="post
button
button  can i give multiple commands on click of a button? if yes how can i do that?? multiple commands can we retriving dat from database, capturing data, moving to next page.. etc
button
button  can i give multiple commands on click of a button? if yes how can i do that?? multiple commands can be retriving dat from database, capturing data, moving to next page.. etc
php code: how to insert manual date and also retrieve records by selecting date field. - Date Calendar
php code: how to insert manual date and also retrieve records by selecting date field.  In PHP, how to insert user input date on mysql db. and also... to get the records by selecting date field in mysql. Please give me a correct code
jdbc insert
jdbc insert  Hi , i want to insert a declared integer variable into a mysql table through jdbc. how to insert that. help me with query... thanks in advance   Here is a java code that connects to database and create
coding of button
coding of button  What is code of fetching the value of button in a textbox using javascript
Insert Operation - WebSevices
Insert Operation  Send the code for Insert Contact in pop up window... If i click one button, pop up window will open, inside the pop up window i insert my contact details(Name,email and etc).So,send the code and solution
DB Insert
DB Insert  How to insert XML data into a database column? Column data type is CLOB
insert query in jsp
insert query in jsp  give me insert code in jsp at run time
JDBC batch insert
JDBC batch insert       JDBC Batch Insert is a set of SQL Statements sent to the database and executed... Insert, An empty array object is linked, whenever a statement object is created