473,406 Members | 2,220 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Problem while insert to data base

plz resolve the issue its not able to inset to database
hereis my code classname addc
Expand|Select|Wrap|Line Numbers
  1. package Log;
  2.  
  3.  
  4.  
  5.  
  6. import javax.swing.*;
  7.  
  8. import java.awt.*;
  9. import java.awt.event.*;
  10. import java.sql.*;
  11.  
  12.  public class addc extends JFrame implements ActionListener{
  13.  
  14.  
  15.     public static void main(String[]args){
  16.         addc panel = new addc();
  17.     panel.setSize(600,400);
  18.     panel.setVisible(true);
  19.     panel.setResizable(false);
  20.     panel.setLocation(400,250);
  21.     }
  22.  
  23.  
  24.     Font f1 = new Font("", Font.BOLD, 10);
  25.  
  26.     JLabel addclient = new JLabel("Add Client");
  27.  
  28.     JLabel lblFName = new JLabel("First Name ");    
  29.     JLabel lblLName = new JLabel("Last Name ");
  30.  
  31.     JLabel lblAddress = new JLabel("Address");
  32.     JLabel lblEmail = new JLabel("Email-id");
  33.     JLabel lblPhone = new JLabel("Phone-No.");
  34.  
  35.  
  36.     JTextField txtFName= new JTextField(20);
  37.     JTextField txtLName = new JTextField(20);
  38.  
  39.     JTextField txtAddress = new JTextField(20);
  40.     JTextField txtEmail = new JTextField(20);
  41.     JTextField txtPhone = new JTextField(20);
  42.  
  43.  
  44.     JButton btnCret = new JButton(new ImageIcon("reg.png"));
  45.  
  46.  
  47.  
  48.     Connection cn;
  49.     Statement st;
  50.     PreparedStatement ps;
  51.     ResultSet rs;
  52.     PreparedStatement ps1;
  53.  
  54.  
  55.     public addc() {
  56.         super("Project");
  57.  
  58.         JPanel pane = new JPanel();
  59.         pane.setLayout(null);
  60.  
  61.  
  62.  
  63.         lblFName.setBounds(105,85,120,25);
  64.         pane.add(lblFName);
  65.         txtFName.setBounds(225,85,150,25);
  66.         pane.add(txtFName);
  67.  
  68.         lblLName.setBounds(105,120,120,25); 
  69.         pane.add(lblLName);
  70.         txtLName.setBounds(225,120,150,25); 
  71.         pane.add(txtLName);
  72.  
  73.         lblAddress.setBounds(105,155,120,25);
  74.         pane.add(lblAddress);
  75.         txtAddress.setBounds(225,155,150,25);
  76.         pane.add(txtAddress);
  77.  
  78.         lblEmail.setBounds(105,190,120,25);
  79.         pane.add(lblEmail);
  80.         txtEmail.setBounds(225,190,150,25); 
  81.         pane.add(txtEmail);    
  82.  
  83.         lblPhone.setBounds(105,225,120,25);
  84.         pane.add(lblPhone);    
  85.         txtPhone.setBounds(225,225,150,25);
  86.         pane.add(txtPhone);    
  87.  
  88.         addclient.setBounds(200,5,250,60);
  89.         addclient.setFont(new Font("Serif", Font.BOLD, 24));
  90.         pane.add(addclient);
  91.  
  92.         lblFName.setForeground(Color.white);
  93.         lblLName.setForeground(Color.white);
  94.         lblAddress.setForeground(Color.white);
  95.         lblPhone.setForeground(Color.white);
  96.         lblEmail.setForeground(Color.white);
  97.  
  98.  
  99.         btnCret.setBounds(129,280,130,38);
  100.         pane.add(btnCret);
  101.         btnCret.addActionListener(this);
  102.  
  103.         addclient.setForeground(Color.white);
  104.  
  105.         JLabel lbl = new JLabel(new ImageIcon("background1.jpg"));
  106.  
  107.         lbl.setBounds(0,0,600,400);
  108.         pane.add(lbl);
  109.  
  110.         setContentPane(pane);
  111.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  112.  
  113.  
  114.         try{
  115.             Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  116.             cn = DriverManager.getConnection("jdbc:odbc:project");
  117.             JOptionPane.showMessageDialog(null,"Successfully Connected to Database","Confirmation", JOptionPane.INFORMATION_MESSAGE);  
  118.  
  119.         }catch(ClassNotFoundException e)  {
  120.              System.err.println("Failed to load driver");
  121.              e.printStackTrace();
  122.          }
  123.          catch(SQLException e){
  124.              System.err.println("Unable to connect");
  125.              e.printStackTrace();
  126.          }
  127.     }
  128.  
  129.             public void actionPerformed(ActionEvent e){
  130.  
  131.                 Object source = e.getSource();
  132.                 if(source == btnCret){
  133.                     String suser =     txtFName.getText();
  134.                     String slname =    txtLName.getText();
  135.                     String saddress =txtAddress.getText();
  136.                     String semail = txtEmail.getText();
  137.                     String sphone = txtPhone.getText();
  138.  
  139.                     if((suser.length()==0 || slname.length()==0 || saddress.length()==0 || semail.length()==0 || sphone.length()==0 )){
  140.                         JOptionPane.showMessageDialog(null,"Some Fields are empty","WARNING",JOptionPane.WARNING_MESSAGE);
  141.                     }
  142.  
  143.                                 try{
  144.  
  145.                 st= cn.createStatement();
  146.  
  147.                 String query="insert into table1 values("+suser+",' "+slname+" ', "+saddress+"' "+semail+" ', "+saddress+")";
  148.                 ps=cn.prepareStatement("INSERT INTO tbl_list " + " (FirstName,LastName,Address,Email,Phoneno) " + " VALUES(?,?,?,?,?)");
  149.                 ps.setString(1,txtFName.getText());
  150.                 ps.setString(2,txtLName.getText());
  151.                 ps.setString(3,txtAddress.getText());
  152.                 ps.setString(4,txtEmail.getText());
  153.                 ps.setString(5,txtPhone.getText());
  154.  
  155.                 ps.executeUpdate();
  156.  
  157.                 JOptionPane.showMessageDialog(null,"Your New Client Info has been successfully Created.","client",JOptionPane.INFORMATION_MESSAGE);
  158.                 txtFName.requestFocus(true);
  159.                 st.close();
  160.  
  161.                     txtFName.setText("");
  162.                     txtLName.setText("");
  163.                     txtAddress.setText("");
  164.                     txtEmail.setText("");
  165.                     txtPhone.setText("");
  166.  
  167.  
  168.                 }
  169.  
  170.                 catch(SQLException sqlEx){
  171.                 JOptionPane.showMessageDialog(null,"General error","client",JOptionPane.INFORMATION_MESSAGE);
  172.                 }
  173.  
  174.                     }
  175.                 }
  176.  
  177.                     }
  178.  
  179.  
  180.  
May 7 '14 #1
2 1183
chaarmann
785 Expert 512MB
Dear pranayf, you have opened 3 posts with (nearly) the same code.
One got deleted because of illegal double-posting, the other is: http://bytes.com/topic/java/answers/...ity-pleasehelp.

In none of these posts you have give us the needed info to help you, even after I requested it. Why, what is the problem?

I already asked two times for the error descripion. The error that you get on the screen (when trying to insert the records in line 147 to 155 on this code listing.)
When you cannot insert records, it could be because the table name or fields are misspelled, you do not have the appropriate database rights, a database field has the wrong type, etc. It could have very many reasons and each reason needs a different solution.
This is not a guessing game. We cannot help you if you do not give more information here (that is the exact error message that was shown to you)
May 7 '14 #2
Could you please share your logs for the error you are getting.
May 7 '14 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: N i E ¶ W i A D o M y | last post by:
Hello. I have a problem with insert a picture (bmp) to data base. I wan't add picture to cell in data base (Access) like double decimal. Someone have a idea how to make this? Please help ...
7
by: David Bear | last post by:
I have a dictionary that contains a row of data intended for a data base. The dictionary keys are the field names. The values are the values to be inserted. I am looking for a good pythonic...
2
by: gaston | last post by:
Hi All I have three data bases with a table each one, what I want to do is to get the data from each table and insert it in a new data base table. The thing is that may be there is going to a...
8
by: slb813 | last post by:
Hello, I am having a problem that I can't seem to work out. I am running Apache 2.2 on a Windows XP platform, using PHP5. I am attempting to insert a row into a MS Access data base with a PHP...
0
by: twilight lover | last post by:
i write a small prog with builder c++ 5 that extract lines from text file then add them into Paradoxe7 table these lines will appear in a DBGrid on the Form by a click on Button1 the file contains...
8
by: Betikci Boris | last post by:
Can not insert data into SQLite3 database through browser however i can easily insert data into my db from konsole, in both attmpts i used php 5.2.6 on 2.6.25.* linux kernel i think there is a...
13
by: deepunarayan | last post by:
Hi I have Problem in ASP. I have created a Multi choice Question page in ASP with Submit button. When I submit my page the User Selected values will be taken to the other page where validation...
0
by: apwuhp | last post by:
We have used a data replication product that has replicated our production data base to another server, both servers are AIX 5.3 operating system and IBM DB2 data bases. The product replicates at the...
0
Vkas
by: Vkas | last post by:
I have a default .aspx form i HAVE 3 TEXT BOX 1 DROPDOWN LIST IN MY DEFAULT PAGE. a access data base file at locaion C:\asp.netdb\feedback.accdb I want to insert the values into the access...
0
by: arianule | last post by:
Could Morning I have been trying very hard to perform a seemingly basic operation which is entering data from a website into an access database(C# code). I dit check the settings on the access...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.