Microsoft] [ODBC驱动程序管理器]无效的字符串或缓冲区长度

时间:2013-07-07 09:13:24

标签: java swing exception

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驱动程序管理器]无效的字符串或缓冲区长度)它工作得更早,直到我重新安装java ...之后它抛出异常 我已经检查了整个程序,编码中没有任何错误,请帮我解决这个问题。

2 个答案:

答案 0 :(得分:1)

我会评论,但我没有足够的声誉。

如果您在环境中更改某些内容而不更改代码,并且出现此错误,则可能是编码不匹配。

从使用4D驱动程序v11的32位计算机切换到使用4D驱动程序v13的64位计算机时,我遇到了同样的问题。打印出我的结果集显示数据未正确解码。在64位机器上更新到v14解决了它。

答案 1 :(得分:1)

这是一个bug,java 1.7,将java更新为java jdk 1.7.70