السلام عليكم ورحمه الله وبركاته ..
اعضاء منتدى الفريق العربي للبرمجه .. كيف حالكم .. إن شاء الله بخير ..
شباب انا عندي برنامج .. فيه واجهه تحتوي على ثلاث بوتون ( botton ) ..البونون الاول ..هوحذف سجل من قاعده بيانات
البوتوون الثاني ... اضافه سجل لقاعده البيانات ..
البوتون الثالث .. هو للتعديل على قاعده اليانات ..
نجي للزببده ... : :D الزبده وهي ... ان كود الحذف والاضافه والنعديل على قاعده البيانات . من غير واجهه يظبط 100 %
لكن مع الواجهه اللي انا صممتهاا .... مايضبط .. والمشكله انه مايعدل على قاعده البيانات ..
وهذا هو الكود ..
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
import java.util.*;
public class DS2Java3T1_0607V2 extends JFrame {
private JButton copyFile1, copyFile2, copyFile3;
public DS2Java3T1_0607V2()
{
super( "DS2 Java3 Term1 2006 2007" );
Container container = getContentPane();
container.setLayout( new FlowLayout() );
copyFile1 = new JButton( "delete records" );
container.add( copyFile1 );
copyFile2 = new JButton( "insert records" );
container.add( copyFile2 );
copyFile3 = new JButton( "update" );
container.add( copyFile3 );
ButtonHandler2 handler = new ButtonHandler2();
copyFile1.addActionListener( handler );
copyFile2.addActionListener( handler );
copyFile3.addActionListener( handler );
setSize( 500, 500 );
setVisible( true );
}
public static void main( String args[] )
{
DS2Java3T1_0607V2 application = new DS2Java3T1_0607V2();
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE );
}
private class ButtonHandler2 implements ActionListener {
public void actionPerformed( ActionEvent event )
{
String n_d;
if ( event.getSource() == copyFile1 )
{
n_d = JOptionPane.showInputDialog("inter the number price to delete");
}
else if ( event.getSource() == copyFile2 )
{
String n = JOptionPane.showInputDialog("Enter the product number");
String l = JOptionPane.showInputDialog("Enter the product label");
String aa = JOptionPane.showInputDialog("Enter the product label2");
String p = JOptionPane.showInputDialog("Enter the product price");
}
else if ( event.getSource() == copyFile3 )
{
String n_u = JOptionPane.showInputDialog("enter the price to update");
}
//
// try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
// }
//
// catch (IOException ioe)
// {
// System.out.println("The error is : " + ioe.getMessage());
// }
//
String url = "jdbc:odbc:MyDSNDataBese";
try {
Connection conn = DriverManager.getConnection(url);
Statement stmt = conn.createStatement();
String Query_d = "delete From MyTable";
System.out.println(Query_d);
String Query = "Insert into MyTable(a , b , c ,Price) select ";
System.out.println(Query);
String Query_u = "Update MyTable set price = price * 1.5";
System.out.println(Query_u);
int i_d = stmt.executeUpdate(Query_d);
if (i_d == 1)
System.out.println("The insertion has been succsesefully completed " + i_d);
else
System.out.println("The insertion has not been succsesefully completed " + i_d);
int i = stmt.executeUpdate(Query);
if (i == 1)
System.out.println("The insertion has been succsesefully completed " + i);
else
System.out.println("The insertion has not been succsesefully completed " + i);
int i_u = stmt.executeUpdate(Query_u);
if (i_u == 1)
System.out.println("The insertion has been succsesefully completed " + i_u);
else
System.out.println("The insertion has not been succsesefully completed " + i_u);
stmt.close();
stmt=null;
conn.close();
conn=null;
System.exit(0);
}
catch (SQLException a)
{System.out.println("My Message : Exception not handled " + a.getMessage() + "\n\r" + a.getSQLState());}
}
}
}ملاحضه .. قاعده الييانات .. على الاكسس ..واسمها MyDSNDataBese
الحفول في الداتابيس ..هي (a , b , c , price)
ارجو المساعده .. واشاكر لكم مقدماا ..
:D