Java database connectivity

Ads
 

Java database connectivity

Hi sir

I need a code to create an application where user enter name in text box and that should be stored in database.

Plz help me out its very urgent.

View Answers

February 14, 2012 at 11:35 AM

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("Insert");
        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);
    }
}

Ads









Related Tutorials/Questions & Answers:
Java database connectivity
Java database connectivity  Hi sir I need a code to create an application where user enter name in text box and that should be stored in database. Plz help me out its very urgent.   import java.sql.*; import java.awt.
database connectivity
database connectivity  how to create database connectivity between HTML and sql server2005
Advertisements
Database Connectivity
Database Connectivity  I tried to establish database connection with sqlserver2008 through GlassFish server. When I set the path of sqljdbc.jar(E:\Glass Fish\glassfish-v2ur1\javadb\lib\sqljdbc.jar) it shows me error
database connectivity
database connectivity  i have written class.forName and getconnection in one method which returns connection string object under particular class and in someother class i want to call that for statement object
database connectivity
database connectivity  i m trying to connect this servlet with database but i m not able to Code is ot giving any error and there is no update in database plsss somebody can help code is here package newpackage; import
database connectivity problem
database connectivity problem  what if client dont have database with them then what is other way to run successfully our programm   Please visit the following link: http://www.roseindia.net/jdbc
Database connectivity Hibernate mysql connection.
Database connectivity Hibernate mysql connection.  How to do database connectivity in Hibernate using mysql
Database Connectivity Withe Oracle
Database Connectivity Withe Oracle  Develop a program to perform the database driven operation like insert, Delete, Update and select. To perform the above operations create one table named Employee. Field Name Field Type EmpId
Java connectivity with MySQL
Java connectivity with MySQL  Java connectivity with MySQL
Database Connectivity Example In Java
Database Connectivity Example In Java In this section we will read about how to establish a connection between Java program and database. To establish a connection between the database and Java program Java provides the JDBC API
Access 2007 database connectivity
Access 2007 database connectivity  i design an application form... source and destination. pls tell me the code of connectivity with access 2007 database using JComboBox.thanks
database connectivity using mysql
database connectivity using mysql  java file: eg1.java package eg; import java.sql.*; public class eg1 { public static void main(String arg[]) throws SQLException { try { String connectionURL = "jdbc:mysql
java connectivity
java connectivity  hi........ Can u help me to do connectivity between java and weka??????? weka is a data mining tool which allows to do prediction, classification etc.... i want to do connectivity between weka and java can u
Oracle Database connectivity probem
Oracle Database connectivity probem  hi Below is the code of oracle database connectivity, when i compile it, it will show the error: oracle.jdbc.driver.OracleDriver I am using netbeans 6.5 and tomcat 6.0 and jdk 1.6 i have
java connectivity
java connectivity  i am trying to add dyanamic rows in the jsp page, when i add the new row the dropdown control value is not coming from database..please help me to overcome this problem
C Program with Database Connectivity
C Program with Database Connectivity  How To Connect MySQL Database in C Program with Graphics
About DataBase Connectivity
About DataBase Connectivity  I want a simple code in which is like two tier application one system have data base and application is running on other system. Pls inform the way hoe to connect both system {I want to run
About DataBase Connectivity
About DataBase Connectivity  I want a simple code in which is like two tier application one system have data base and application is running on other system. Pls inform the way hoe to connect both system {I want to run
code to establish jdbc database connectivity in jsp
code to establish jdbc database connectivity in jsp  Dear sir, i'm in need of code and procedure to establish jdbc connectivity in jsp
code to establish jdbc database connectivity in jsp
code to establish jdbc database connectivity in jsp  Dear sir, i'm in need of code and procedure to establish jdbc connectivity in jsp
sql connectivity through java
sql connectivity through java  i want an example for java db through sql connection. Thanks in advance
database connectivity using jsp code
database connectivity using jsp code  i have two tables employee and adduser insert into adduser(Emp_Id,Ename,Designation,Password,ReTypePassword)values('6867678po',(select Ename from employee),(select Designation from employee
online database connectivity issue from JSP page .
online database connectivity issue from JSP page .  Hi; Everything working fine in localhost , but facing a simple problem in connectivity with database from my web site. In my local host-- when I am typing
online database connectivity issue from JSP page .
online database connectivity issue from JSP page .  Hi; Everything working fine in localhost , but facing a simple problem in connectivity with database from my web site. In my local host-- when I am typing following code
online database connectivity issue from JSP page .
online database connectivity issue from JSP page .  Hi; Everything working fine in localhost , but facing a simple problem in connectivity with database from my web site. In my local host-- when I am typing following code
Java to SQL Server Connectivity
Java to SQL Server Connectivity  Hi, heres my code private void... with sql server connectivity at the background to save the data. Now, after... the connectivity wrong. Kindly help me resolve this issue ASAP. Thank you
connectivity
connectivity  how to connect java with database
JDBC access database
is a Java Database Connectivity. The JDBC Connectivity provides API classes and interfaces for connecting the front end in Java application with database connections... end of the Java application to the backend database. In case
java servlet connectivity problem with access
java servlet connectivity problem with access  Import java.sql javax.servlet //all packages entered try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection("jdbc
JDBC Connectivity Code In Java
JDBC Connectivity Code In Java      ... in understanding JDBC Connectivity Code in Java. In this program, the code returns you the time set by the driver to connect url and database. For this we
java database
java database  help me with this...i never learn build java database... to design and implement objects needed for a program that maintains a database.../teacher information, search it, alter it, etc. The database is maintained as a list

Ads