UCAExc:::3.0.7 row column count mismatch - java

I have some codes for doing my project. There is a access database that have some tables and records. I'm taking this records from access database and I'm creating MS Word document with them. My codes like this
public static void partoff(String SalesOrder)
{
try {
ResultSet deneme4,deneme5,deneme6,deneme,deneme0,deneme10,deneme11 = null;
deneme10=sorgu.executeQuery("SELECT GroupName,ID From TableRun Where LID IN (Select DISTINCT strLID from TableResult Where strSO='"+SalesOrder+"') ORDER BY ID");
ArrayList all_groups=new ArrayList();
while(deneme10.next()) {
all_groups.add(deneme10.getString("GroupName"));
//System.out.println(all_groups.size());
}
ArrayList LIDs=new ArrayList();
deneme11=sorgu.executeQuery("SELECT LID,ID FROM TableRun WHERE GroupName IN (SELECT GroupName,ID From TableRun Where LID IN (Select DISTINCT strLID from TableResult Where strSO='"+SalesOrder+"')) ORDER BY ID");
while(deneme11.next())
{
LIDs.add(deneme11.getString("LID"));
System.out.println(LIDs.size());
}
for(int qq=0; qq<all_groups.size(); qq++) {
deneme4=sorgu.executeQuery("SELECT * FROM TableResult WHERE strSO='" + SalesOrder + "' AND strLID='"+LIDs.get(sayac)+"'");
deneme5=sorgu.executeQuery("SELECT * FROM TablePARTON WHERE strSO='" + SalesOrder + "' AND strLID='"+LIDs.get(sayac)+"'");
deneme6=sorgu.executeQuery("SELECT * FROM TableIW59 WHERE strSO='" + SalesOrder + "' AND strLID='"+LIDs.get(sayac)+"'");
while(deneme4.next()) {
System.out.println(off[satir1][sayac2+8]=deneme4.getString("DefectDes"));
if(!off[satir1][sayac2+8].equalsIgnoreCase("Not Disassembled"))
{
off[satir1][sayac2]=deneme4.getString("strTASK");
off[satir1][sayac2+1]=deneme4.getString("strLID");
off[satir1][sayac2+2]=deneme4.getString("strPN");
off[satir1][sayac2+3]=deneme4.getString("intQPE");
off[satir1][sayac2+4]=deneme4.getString("intSV");
off[satir1][sayac2+5]=deneme4.getString("intIS");
off[satir1][sayac2+6]=deneme4.getString("intRS");
off[satir1][sayac2+7]=deneme4.getString("intREP");
off[satir1][sayac2+8]=deneme4.getString("DefectDes");
satir1++;
}
else {
//System.out.println(deneme.getString("GroupName"));
//satir1=0;
//deneme4.next();
}
}
while(deneme5.next())
{
onn[satir2][sayac2]=deneme5.getString("strPN");
onn[satir2][sayac2+1]=deneme5.getString("intNewOnQty");
onn[satir2][sayac2+2]=deneme5.getString("intRepOnQty");
onn[satir2][sayac2+3]=deneme5.getString("intSVOnQty");
onn[satir2][sayac2+4]=deneme5.getString("strRemark");
satir2++;
}
while(deneme6.next())
{
if(!deneme6.getString("strNotifType").equals("ER")) {
dispon[satir3][sayac2]=deneme6.getString("strNotifType");
dispon[satir3][sayac2+1]=deneme6.getString("strPN");
dispon[satir3][sayac2+2]=deneme6.getString("strQty");
dispon[satir3][sayac2+3]=deneme6.getString("strCodeText");
dispon[satir3][sayac2+4]=deneme6.getString("strGroupText");
dispon[satir3][sayac2+5]=deneme6.getString("strShortText");
dispon[satir3][sayac2+6]=deneme6.getString("strLongText");
satir3++;
}
}
if(satir3>0) {
int x=0;
int y=0;
int q=0;
for(int i=0; i<satir3; i++) {
j=i+1;
while(j<=satir3) {
if(dispon[i][1].equals(dispon[j][1]) && dispon[i][3].equals(dispon[j][3])&& dispon[i][4].equals(dispon[j][4])){
x = Integer.parseInt(dispon[i][2]);
y = Integer.parseInt(dispon[j][2]);
q = x+y;
dispon[i][2]=Integer.toString(q);
dispon[j][0]="boss";
}
j++;
}
}
}
disponsatir=0;
for(int i = 0; i < satir3; i++)
{
for(int j = 0; j<7 ;j++)
{
if(!dispon[i][0].equals("boss"))
{
dispon_new[disponsatir][j]=dispon[i][j];
if(j==6) disponsatir++;
}
}
}
sayac++;
if(!all_groups.get(qq).equals(all_groups.get(qq+1))) {
create_table1(satir1,all_groups.get(qq).toString());
sayac3=0;
sayac2=0;
satir1=0;
satir2=0;
satir3=0;
}
}
System.out.println("Success");
} catch (Exception e) {
// TODO: handle exception
System.out.println("NOT Successfully");
System.out.println(e.getLocalizedMessage());
}
}
It was working nicely yesterday. I changed something in codes but I don't remember what is it. After then I tried to run my codes, I'm getting this error.
UCAExc:::3.0.7 row column count mismatch
Why I'm getting this error?

Related

How to display and add tasks to file according to priorities using Java

I need to display/list the contents of a txt file in the ascending order of priority. So, should I need to take a seperate input for priority of task or can I splice the input line?
private static void show() {
String[] items = getData("task.txt");
if (items.length == 0) {
System.out.println("There are no pending tasks!");
} else {
for (int i = items.length - 1; i >=0; i--) {
System.out.printf("[%d] %s\n", i + 1, items[i]);
}
}
My getData looks like this:
private static String[] getData(String file) {
ArrayList<String> dataList = new ArrayList<>();
Scanner s=null;
try {
s = new Scanner(new FileReader(file));
while (s.hasNextLine()){
dataList.add(s.nextLine());
}s.close();
} catch (Exception e) {
System.out.println("Problem to open \"task.txt\".");
} finally {
if (s != null) {
try {
s.close();
} catch (Exception e) {
}
}
}
String[] items = new String[dataList.size()];
for (int i = 0; i < items.length; i++) {
items[i] = dataList.get(i);
}
return items;
}
Input:
10 the thing i need to do
5 water the plants
11 clean house
Output: 5 water the plants
10 the thing i need to do
11 clean house
You can just sort the ArrayList datalist:
(I am assuming that the "priority item" format is already in it)
dataList.sort((o1, o2) -> {
Integer priority1 = Integer.parseInt(o1.split(" ")[0]);
Integer priority2 = Integer.parseInt(o2.split(" ")[0]);
return priority1.compareTo(priority2);
});
Put this right after the try-catch-finally-block.

RadioButton value Increment decrement using Java

this is a online exam system. if the answer is correct marks increment by 1 it is work correctly at the same question second time select wrong answer i i need decrement the value
int marks;
String cor;
public void answerCheck()
{
String answerAnswer="";
if(r1.isSelected())
{
answerAnswer = r1.getText();
}
else if(r2.isSelected())
{
answerAnswer = r2.getText();
}
else if(r3.isSelected())
{
answerAnswer = r3.getText();
}
else if(r4.isSelected())
{
answerAnswer = r4.getText();
}
if(answerAnswer.equals(cor))
{
marks = marks + 1;
String Marks = String.valueOf(marks);
txtc.setText(Marks);
}
else if(!answerAnswer.equals(cor))
{
marks = marks - 1;
String Marks = String.valueOf(marks);
txtc.setText(Marks);
}
else
{
marks =0;
}
}
i am loading all data from the database correct answer also i am loading
Database Load
public void Connection()
{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost/onlineex","root","");
String query = "select * from questions";
pst = con.prepareStatement(query);
rs = pst.executeQuery();
while(rs.next())
{
txtqu.setText(rs.getString("id"));
txtques.setText(rs.getString("question"));
r1.setText(rs.getString(3));
r2.setText(rs.getString(4));
r3.setText(rs.getString(5));
r4.setText(rs.getString(6));
cor = rs.getString(7);
}
}
i have a button call next
try
{
if(rs.previous())
{
txtques.setText(rs.getString("question"));
r1.setText(rs.getString(3));
r2.setText(rs.getString(4));
r3.setText(rs.getString(5));
r4.setText(rs.getString(6));
cor=rs.getString(7);
}
else
{
JOptionPane.showMessageDialog(this, "This is first record of student");
}
answerCheck();
}
i have button call previous
if(rs.next())
{
txtques.setText(rs.getString("question"));
r1.setText(rs.getString(3));
r2.setText(rs.getString(4));
r3.setText(rs.getString(5));
r4.setText(rs.getString(6));
cor=rs.getString(7);
}
else
{
JOptionPane.showMessageDialog(this, "This is first record of student");
}
answerCheck();
Firstly there is a Logical error in last else which will never execute because either answer is correct or wrong there is no third condition.
String cor;
public void answerCheck()
{
String answerAnswer="";
if(r1.isSelected())
{
answerAnswer = r1.getText();
}
else if(r2.isSelected())
{
answerAnswer = r2.getText();
}
else if(r3.isSelected())
{
answerAnswer = r3.getText();
}
else if(r4.isSelected())
{
answerAnswer = r4.getText();
}
if(answerAnswer.equals(cor))
{
marks = marks + 1;
String Marks = String.valueOf(marks);
txtc.setText(Marks);
}
else if(!answerAnswer.equals(cor) || ((r1.isSelected() ||
r2.isSelected() || r3.isSelected() || r4.isSelected()))
{
marks = marks - 1;
String Marks = String.valueOf(marks);
txtc.setText(Marks);
}
}

How to add and subtract value of sum after adding/removing a row from JTable

I have the code for adding and removing a single row for my JTable but it causes problems like not providing accurate calculation of overall sum and subtraction after removing it from the JTable. The JTable serves as a "cart" for adding and removing items in the cart.
The add to cart button for adding a row to the cart:
if (e.getSource() == movebutton) {
TableModel model1 = productTable.getModel();
int index[] = productTable.getSelectedRows();
Object[] row = new Object[4];
DefaultTableModel model2 = (DefaultTableModel) cartTable.getModel();
for (int i = 0; i < index.length; i++) {
row[0] = model1.getValueAt(index[i], 0);
row[1] = model1.getValueAt(index[i], 1);
row[2] = model1.getValueAt(index[i], 2);
model2.addRow(row);
getSum();
}
The code where it adds the overall items:
public void getSum() { //column 02 is where the item's prices are listed
for (int i = 0; i < cartTable.getRowCount(); i++) {
total += Double.parseDouble(cartTable.getValueAt(i, 2).toString());
}
cartAmount.setText("Total: P " + Double.toString(total));
}
}
The remove an item from the cart button code:
try {
for (int i = 0; i < cartTable.getRowCount(); i++) {
total = total - Double.parseDouble(cartTable.getValueAt(i, 2).toString());
}
cartAmount.setText("Total: P " + Double.toString(total));
if (total <= 0.0) {
total = 0.0;
}
{
int getSelectedRowForDeletion = cartTable.getSelectedRow();
model2.removeRow(getSelectedRowForDeletion);
JOptionPane.showMessageDialog(null, "Item removed from cart");
}
} catch (NumberFormatException ex) {
ex.printStackTrace();
} catch (ArrayIndexOutOfBoundsException ex) {
}
}
Here are some pics when adding and remove an item:
How can I also make the remove button to not work when no row is selected? Like ask the user to select a row before deletion? Also remove the possibility of having negative sum calculations. Thank you
I solved it:
The add to cart button:
if (e.getSource() == movebutton) {
try {
int index[] = productTable.getSelectedRows();
Object[] row = new Object[4];
for (int i = 0; i < index.length; i++) {
row[0] = model.getValueAt(index[i], 0);
row[1] = model.getValueAt(index[i], 1);
row[2] = model.getValueAt(index[i], 2);
model2.addRow(row);
}
DefaultTableModel t = (DefaultTableModel) productTable.getModel();
int selectedRow = productTable.getSelectedRow();
{
total += Double.parseDouble(t.getValueAt(selectedRow, 2).toString());
}
cartAmount.setText("Total: P " + Double.toString(total));
}catch (ArrayIndexOutOfBoundsException a) {
}
}
The remove button:
if (e.getSource() == remove) {
try {
DefaultTableModel t = (DefaultTableModel) cartTable.getModel();
int getSelectedRowForDeletion = cartTable.getSelectedRow();
if (getSelectedRowForDeletion >= 0) {
int selectedRow = cartTable.getSelectedRow();
total -= Double.parseDouble(t.getValueAt(selectedRow, 2).toString());
cartAmount.setText("Total: P " + Double.toString(total));
model2.removeRow(getSelectedRowForDeletion);
JOptionPane.showMessageDialog(null, "Item removed from cart!");
} else {
JOptionPane.showMessageDialog(null, "Select an item to remove.");
}
} catch (ArrayIndexOutOfBoundsException a) {
}
}
I removed the for loop when adding the values as it will just add the next item in the productTable. Same goes for the remove button.

chess in GWT+MVP and trying to store states in the local storage

I have done this till now
public void addStorage() {
stockStore = Storage.getLocalStorageIfSupported();
if (stockStore != null) {
stockStore.setItem(("Index" + index), ("state" + HistoryCount));
stockMap.put(("Index" + index), ("state" + HistoryCount));
}
}
public void loadStorage() {
String s;
stockStore = Storage.getLocalStorageIfSupported();
if (stockStore != null) {
stockMap = new
StorageMap(stockStore);
for (int i = 0; i < stockStore.getLength(); i++) {
if (stockMap.containsValue(index)) {
s = stockStore.getItem("Index" + index);
state = stateRecord.get(s);
clearHighlights();
setState(state);
break;
}
}
}
}
I have no idea what am I missing. These two functions are called by their handlers. Load and Save. load storage will load the stored state of chess and save will save the current chess state.
Possibly you have error here in stockMap.containsValue(index) but should be stockMap.containsValue("Index" + index), the corrected version:
for (int i = 0; i < stockStore.getLength(); i++) {
if (stockMap.containsValue("Index" + index)) {
s = stockStore.getItem("Index" + index);
state = stateRecord.get(s);
clearHighlights();
setState(state);
break;
}
}

Unable to update value of gobal variable in threads

I am not able to update the value of a global variable in a function which is called continuously by a thread
The function code is:
public void readMessages()
{
if (srv.getServiceStatus() == Service.ServiceStatus.STARTED) {
try {
InboundMessage msg = null;
java.util.LinkedList<InboundMessage> list = new java.util.LinkedList<InboundMessage>();
srv.readMessages(list, InboundMessage.MessageClasses.UNREAD);
int checkArray = list.size();
for (int i = 0; i < list.size(); i++) {
msg = list.get(i);
System.out.println("New incoming message from: " + msg.getOriginator() +" : \t" + msg.getText() + "\n");
saveSMS(msg.getOriginator(),msg.getText());
if (checkArray == 0) {
messageArray = new String [4];
for (int j = 0 ; j<4 ; j++) {
messageArray[j] = "";
}
}
if (noOfSms < 4) {
messageArray[noOfSms] = msg.getText();
noOfSms = noOfSms + 1;
}
if (noOfSms == 3) {
Receiver r = new Receiver ();
r.Processing_ReceivedSMS(msg.getText(),msg,messageArray);
}
}
}
catch(Exception e){
e.printStackTrace();
}
}
}
Here noOfSms is the global variable but its value does not change.
The function from which readMessage is called is this:
public void run(){
while (true){
readMessages();
try {
t.sleep(5000);
user_status=2;
} catch (InterruptedException e) {
System.out.println("Thread Pause Exception");
}
}
}
What's the reason behind it and what to do about it?
Since you invoke this method from thread/s there are two reasons why your variable does not get updated.
the code inside readMessages() might throw any Exception before your variable gets updated
there is a possibility that your variable never updates because it is located inside if blocks. Check the initial value of it so it can pass the if-condition

Categories