• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

jdbc odbc issue?

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what is the wrong in these code?
code successfully run but record is not deleted from database
my database is ms access 2007
database columns are as follow
Building_no Customer_Name
but record is not deleted
here is the code


please correct me if i was wrong or tell me suggestion what to do?





thanks in advanced for the help...
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The code asks the database to delete all records where the Building_No code contains the string "Building_No". Presumably there aren't any such records.

But presumably that isn't what you wanted. I expect you want to get some value from the GUI and use that instead of the string "Building_No".
 
Devendra Ghag
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks man...
but i have one more query related to these

a customer having multiple news paper in his account, if i want to delete particular paper from customer
how to do.
here is the code but i finding difficulty to use it


import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import javax.swing.*;

public abstract class delete_paper extends JFrame implements ActionListener
{
JTextField textFieldId;
JLabel l1;
JLabel l3;
JLabel l5;
JLabel l6;
JComboBox combo;
String paper[] = {"Navakal","SandhyaKal","Pudhari","MidDay","Inqlab","BusinessLine","Mumbai Samachar","GujrajSamachar","KarnatakMalla","Vartahar","PunyaNagari"};
JButton b2;
Container c = getContentPane();
delete_paper()
{
super("Shree DattaDigambar Samarth");
setBounds(140,250,777,555);
c.setLayout(null);
textFieldId = new JTextField();
l1 = new JLabel("New Customer Entry");
l3 = new JLabel("Customer Name");
l5 = new JLabel("Paper");
combo = new JComboBox(paper);
l1.setBounds(10,10,340,20);
l3.setBounds(110,20,140,70);
l5.setBounds(400,50,140,20);
textFieldId.setBounds(10,70,70,20);
combo.setBounds(400,70,130,20);
b2 = new JButton("Ok");
b2.setBounds(10,160,50,20);
c.add(combo);
c.add(b2);
c.add(l1);
c.add(l3);
c.add(l5);
c.add(textFieldId);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
b2.addActionListener(this);
}
public static void main(String[] args)
{
delete_paper ap=new delete_paper() {};
}
public void actionPerformed(ActionEvent e)
{

System.out.println("You clicked the button");
if(e.getSource()==b2)
{
try
{
Connection con;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:devendra");
try
{

java.sql.Statement st = con.createStatement();
PreparedStatement ps = con.prepareStatement("DELETE from Customer WHERE Customer_Id = ? and Paper_Name = ? ");
ps.setString(1,textFieldId.getText());
ps.setString(4,combo.getSelectedItem().toString());
ps.executeUpdate();
JOptionPane.showMessageDialog(null,"You successfully Enter the Entry");
}
catch (SQLException s)
{
System.out.println("SQL code does not execute.");
JOptionPane.showMessageDialog(null,"Please Enter the Detail Correctly");
}
}
catch (ClassNotFoundException | SQLException ee)
{
System.out.println("Error:connection not created");
JOptionPane.showMessageDialog(null,"Please Enter the Detail Correctly");
}
}
}
}


thanks in advanced for the help??
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic