2013-07-07 68 views
1
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"); 
      } 
     } 
    } 
} 

這產生一個異常(微軟] [ODBC驅動程序管理器]無效的字符串或緩衝區長度),這是早期的工作,直到我重新安裝了java的... ...之後,它會拋出一個異常 我已經檢查過整個程序,在編碼方面沒有任何問題,plz幫我解決了這個問題。微軟] [ODBC驅動程序管理器]無效的字符串或緩衝區長度

+0

可能是你,因爲32位的64位兼容性越來越... 嘗試檢查操作系統類型和Java類型以及接入類型... – Iftikhar

+0

這將是明智的,如果你用'Stacktrace'更新你的問題,例外。而且,如果你嘗試恢復到之前使用的版本,檢查結果是否正常? –

回答

1

我會評論,但我沒有足夠的聲譽。

如果你在你的環境中改變了一些東西,而沒有改變代碼,並且你得到這個錯誤,那麼它可能是一種編碼不匹配。

從具有4D驅動程序v11的32位機器切換到具有4D驅動程序v13的64位機器時,我遇到同樣的問題。打印出我的結果集顯示數據沒有正確解碼。在64位機器上更新到v14解決了它。

1

這是一個錯誤,JAVA 1.7,更新Java到Java JDK 70年7月1日

相關問題