package project;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import java.sql.*;
import javax.swing.JOptionPane;
public class newadmition implements ActionListener
{
private JFrame f;
private JLabel lb,lb1,lb2,lb3,lb4,lb5,lb6,lb7;
private JButton bt,bt2,bt3;
private JTextField tx1,tx3,tx4,tx5,tx6;
private JComboBox cb,cb2;
private Connection con;
String s[] ={"6","7","8","9","10","11","12"};
String g[]={"Jalandhar","Ludhiana","Chandigarh","Patiala"};
public newadmition()
{
f=new JFrame("New Admition");
lb=new JLabel("Enter the required information");
lb.setFont(new Font("Serif",Font.PLAIN, 18));
lb1=new JLabel("Name");
lb2=new JLabel("Class");
lb3=new JLabel("ID");
lb4=new JLabel("City");
lb5=new JLabel("Address");
lb6=new JLabel("Contact");
lb7=new JLabel("Marks");
tx1=new JTextField();
tx4=new JTextField();
tx5=new JTextField();
tx6=new JTextField();
cb=new JComboBox(s);
tx3=new JTextField();
cb2=new JComboBox(g);
bt2=new JButton("Submit");
bt3=new JButton("Back");
bt2.addActionListener(this);
bt3.addActionListener(this);
}
public void launch()
{
f.setLayout(null);
f.setSize(420,500);
f.setLocation(400,100);
f.add(lb);
f.add(lb1);
f.add(lb2);
f.add(lb3);
f.add(lb4);
f.add(lb5);
f.add(lb6);
f.add(lb7);
f.add(tx1);
f.add(cb);
f.add(tx3);
f.add(tx4);
f.add(tx5);
f.add(tx6);
f.add(cb2);
f.add(bt2);
f.add(bt3);
lb.setBounds(10,10,300,40);
lb1.setBounds(40,80,100,25);
tx1.setBounds(120,80,200,25);
lb2.setBounds(40,130,100,25);
cb.setBounds(120,130,200,25);
lb3.setBounds(40,180,100,25);
tx3.setBounds(120,180,200,25);
lb4.setBounds(40,230,100,25);
cb2.setBounds(120,230,200,25);
lb5.setBounds(40,280,100,25);
tx4.setBounds(120,280,200,25);
lb6.setBounds(40,330,100,25);
tx5.setBounds(120,330,200,25);
lb7.setBounds(40,380,100,25);
tx6.setBounds(120,380,200,25);
bt2.setBounds(300,420,80,25);
bt3.setBounds(10,420,80,25);
f.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource().equals(bt3))
{
f.dispose();
}
if(e.getSource().equals(bt2))
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con =DriverManager.getConnection("jdbc:odbc:project","sa","123456");
PreparedStatement stmt= con.prepareStatement("insert into classrecords (Name,ID,City,Contact,Class,Marks,Address) values(?,?,?,?,?,?,?)");
stmt.setString(1,tx1.getText());
stmt.setInt(2,Integer.parseInt(tx3.getText()));
stmt.setString(3,cb2.getSelectedItem().toString());
stmt.setInt(4,Integer.parseInt(tx5.getText()));
stmt.setString(5,cb.getSelectedItem().toString());
stmt.setInt(6,Integer.parseInt(tx6.getText()));
stmt.setString(7,tx4.getText());
stmt.executeUpdate();
JOptionPane.showConfirmDialog(f,"Data Saved");
}
catch(Exception ex)
{
JOptionPane.showConfirmDialog(f,"This ID already Exist");
}
}
}
}
これにより例外が発生します(Microsoft] [ODBC Driver Manager]無効な文字列またはバッファ長)Javaを再インストールするまで以前は機能していました...その後、例外がスローされますプログラム全体をチェックしましたが、何も問題はありませんコーディングで、これを解決するのを手伝ってください。