- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有以下代码,可以正常编译,但是当它运行时,它会抛出 java.lang.ArrarIndexOutOfBoundsException:11 异常,如果您能帮助解决问题,那将是一个很大的帮助。
代码是:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class Pro implements ActionListener
{
JTextField t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13;
JButton b1,b2;
public Pro()
{
JFrame f = new JFrame();
JLabel l1 = new JLabel("SNo.");
JLabel l2 = new JLabel("OPANo");
JLabel l3 = new JLabel("CollegeName");
JLabel l4 = new JLabel("ProjectName");
JLabel l5 = new JLabel("SanctionNoDate");
JLabel l6 = new JLabel("TotalOutlayInLakhs)");
JLabel l7 = new JLabel("ProjectDuration");
JLabel l8 = new JLabel("AmountReleased");
JLabel l9 = new JLabel("BalanceToBeReleased");
JLabel l10 = new JLabel("PRSGsHeld");
JLabel l11 = new JLabel("NextPRSGDue");
JLabel l12 = new JLabel("CompletionMonth");
JLabel l13 = new JLabel("Status");
t1 = new JTextField(20);
t1.setEnabled(false);
t2 = new JTextField(20);
t3 = new JTextField(20);
t4 = new JTextField(20);
t5 = new JTextField(20);
t6 = new JTextField(20);
t7 = new JTextField(20);
t8 = new JTextField(20);
t9 = new JTextField(20);
t10 = new JTextField(20);
t11 = new JTextField(20);
t12 = new JTextField(20);
t13 = new JTextField(20);
b1 = new JButton("Reset");
b2 = new JButton("Insert");
b1.addActionListener(this);
b2.addActionListener(this);
JPanel p1 = new JPanel();
p1.add(l1);p1.add(t1);
p1.add(l2);p1.add(t2);
p1.add(l3);p1.add(t3);
p1.add(l4);p1.add(t4);
p1.add(l5);p1.add(t5);
p1.add(l6);p1.add(t6);
p1.add(l7);p1.add(t7);
p1.add(l8);p1.add(t8);
p1.add(l9);p1.add(t9);
p1.add(l10);p1.add(t10);
p1.add(l11);p1.add(t11);
p1.add(l12);p1.add(t12);
p1.add(l13);p1.add(t13);
p1.add(b1);p1.add(b2);
p1.setLayout(new GridLayout(14,2));
f.add(p1);
f.pack();
f.setResizable(false);
f.setVisible(true);
}
public int getMaxSNO()
{
int sno=0;
String path ="jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=doit.mdb";
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection(path);
Statement stat = con.createStatement();
ResultSet rs = stat.executeQuery("SELECT max(Sno) from project");
if(rs.next())
{
sno=rs.getInt(1);
}
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, e.toString());
}
return sno;
}
public boolean isAlpha(String str)
{
boolean result = false;
for(int i=0;i!=str.length();i++)
{
int ch = str.charAt(i);
if((ch>=65 && ch<=91) || (ch>=97 && ch<=122))
{
result = true;
}
else
{
result = false;
break;
}
}
return result;
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)
{
t1.setText("");
t2.setText("");
t3.setText("");
t4.setText("");
t5.setText("");
t6.setText("");
t7.setText("");
t8.setText("");
t9.setText("");
t10.setText("");
t11.setText("");
t12.setText("");
t13.setText("");
}
else if(e.getSource()==b2)
{
String name = t3.getText();
boolean b1 = isAlpha(name);
if(b1)
{
try
{
String path ="jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=doit.mdb";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection(path);
PreparedStatement ps = con.prepareStatement("INSERT into project(OPANo, CollegeName, ProjectName, SanctionNoDate, TotalOutlayInLakhs, ProjectDuration, AmountReleased, BalanceToBeReleased, PRSGsHeld, NextPRSGDue, CompletionMonth, Status) VALUES(?,?,?,?,?,?,?,?,?,?,?)");
ps.setInt(1,Integer.parseInt(t2.getText()));
ps.setString(2, t3.getText());
ps.setString(3, t4.getText());
ps.setString(4, t5.getText());
ps.setString(5, t6.getText());
ps.setString(6, t7.getText());
ps.setString(7, t8.getText());
ps.setString(8, t9.getText());
ps.setString(9, t10.getText());
ps.setString(10, t11.getText());
ps.setString(11, t12.getText());
ps.setString(12, t13.getText());
int rows = ps.executeUpdate();
if(rows>0)
{
con.close();
int sno=getMaxSNO();
t1.setText(String.valueOf(sno));
JOptionPane.showMessageDialog(null, "Data Inserted");
}
else
{
JOptionPane.showMessageDialog(null, "Failed");
}
con.close();
}
catch(Exception ae)
{
JOptionPane.showMessageDialog(null, ae.toString());
}
}
else
{
JOptionPane.showMessageDialog(null, "Invalid Name");
}
}
}
public static void main(String args[])
{
Pro obj = new Pro();
}
}
最佳答案
我怀疑这就是问题所在:
// Reformatted
PreparedStatement ps = con.prepareStatement(
"INSERT into project(OPANo, CollegeName, ProjectName, SanctionNoDate, " +
"TotalOutlayInLakhs, ProjectDuration, AmountReleased, " +
"BalanceToBeReleased, PRSGsHeld, NextPRSGDue, CompletionMonth, Status) " +
"VALUES(?,?,?,?,?,?,?,?,?,?,?)");
计算问号,然后计算您尝试指定的值的数量...
(然后请注意,您正在调用 ps.setString(12, t13.getText())
- 确认您确实意味着有 12 个参数,而不是 11 个...)
关于java.lang.ArrarIndexOutOfBoundsException :11,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6760854/
在 Tomcat 6/Ubuntu 12.04 上启动 Grails 2.1.0 应用程序时出现以下错误。 Error 500 - Internal Server Error. groovy.lang
在运行 Storm 拓扑时,我收到此错误。拓扑完美运行 5 分钟,没有任何错误,然后失败。我正在使用 Config.TOPOLOGY_TICK_TUPLE_FREQ_SECS as 300 sec i
我有一个 jsp 代码在其中一台机器上运行良好。但是当我复制到另一台机器时,我得到了这个 no such method found 异常。我是 Spring 的新手。有人可以解释我错过了什么吗? 以下
已关闭。此问题需要 debugging details 。目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and the
我的代码在下面给出了一个错误; Exception in thread "main" java.lang.NoSuchMethodError: com/myApp/Client.cypherCBC(L
我正在尝试一个 Restful web 服务示例,所以当我要访问 url 时,我遇到了异常 java.lang.NoSuchMethodError: jersey.repackaged.com.goo
我正在将一个 Spring web 项目转换为一个 Maven 项目,但我收到了这个错误: java.lang.NoSuchMethodError: org.jboss.logging.Logger.
在我的项目中,我有一个像这样的枚举: public enum MyEnum { FIRST(1), SECOND(2); private int value; private MyEnum(int v
我创建了这个简单的示例,用于读取 Linux 正常运行时间: public String getMachineUptime() throws IOException { String[] di
我正在使用 Eclipse,并且正在使用 Java。我的目标是使用 bogoSort 方法对 vector 进行排序在一个 vector (vectorExample)中适应我的 vector 类型,
我正在运行以下查询。它显示一条错误消息。如何解决这个错误? ListrouteList=null; List companyList = session.createS
我有以下模型类: @Entity @Table(name="user_content") @org.hibernate.annotations.NamedQueries({ @org.
我有那个错误。这是我的代码: GmailSettingsService service = new GmailSettingsService(APPLICATION_NAME, DOMAIN_NAME
实际上我在执行我的java程序时遇到了下面提到的错误 Exception in thread "pool-1-thread-1" java.lang.ClassCastException: jav
java.lang.ClassCastException: java.lang.Float cannot be cast to java.lang.String 我在以下代码中遇到此异常: Strin
我正在尝试从 linkedhashset 中检索随机元素。下面是我的代码,但它每次都给我异常。 private static void generateRandomUserId(Set userIds
我已经完成了 Android 中的代码: List spinnerArray = new ArrayList(); for (int i = 0; i item = (LinkedTreeMap)
这个问题已经有答案了: Explanation of ClassCastException in Java (12 个回答) 已关闭 6 年前。 我已经编写了 java 到 Json 的代码,同时从页
这个问题在这里已经有了答案: ClassCastException java.lang.Long cannot be cast to clojure.lang.IFn (4 个答案) 关闭 6 年前
我在运行时遇到问题来编译这段代码,这给我一个错误,java.lang.Integer 无法转换为 Java.lang.Double。如果有人帮助我更正此代码,我将非常高兴 double x; pu
我是一名优秀的程序员,十分优秀!