Thanks very much guys..........
i don't understand what is happening to my jsf application.
It runs perfectly but don't insert the array of byte in the blob field
of mysql db...
can you help me finding the problem?
Thanks
my java application works fine,but i don't understand while,going in my
jsf application the application runs but don't insert value into table
of my db....can someone help me?
This is the bean i invoke when i clic upload button
package giu;
import org.apache.myfaces.custom.fileupload.UploadedFile;
import giu.Head;
import giu.Riga;
import java.sql.*;
import java.util.*;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.Vector;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import java.security.MessageDigest;
//import java.security.NoSuchAlgorithmException;
import java.io.*;
public class MyBean {
private UploadedFile myFile;
private String geneid = null;
private static int row = 0;
private static int numberOfNumericColumns = 0;
private static int col = 0;
String[] intest = null;
private ArrayList rows = new ArrayList();
Head h;
Riga r;
byte middlerow = ' ';
byte endrow = ';';
byte[] data = null;
Vector temp = new Vector(100000);
String g = null;
Riga r;
Double val[];
public boolean insRighe(Riga nuovo) {
return rows.add(nuovo);
}
public List stampaRows() {
return rows;
}
public Head stampaHead() {
return h;
}
public boolean insRighe(Riga nuovo) {
return rows.add(nuovo);
}
public List stampaRows() {
return rows;
}
public Head stampaHead() {
return h;
}
public byte[] getdata() {
return data;
}
public String carica() throws IOException {
System.out.println("eccomi0");
FileReader reader = new FileReader(fileName);
System.out.println("eccomi99");
BufferedReader br = new BufferedReader(reader);
String line = null;
System.out.println("eccomi1");
while ((line = br.readLine()) != null) {
line = line.replace(',', '.');
StringTokenizer st = new StringTokenizer(line);
numberOfNumericColumns = (st.countTokens() - 1);
col = (numberOfNumericColumns + 1);
//se siamo nella prima riga(contatore segna 0)
if (row == 0) {
intest = new String[col];
int j = 0;
while (st.hasMoreTokens()) {
intest[j] = (st.nextToken().trim());
j++;
}
h = new Head(intest);//crei l'oggetto head
String[] qa = h.getHvalues();
String asd = "";
for (int i = 0; i <= qa.length - 1; i++) {
asd = asd.concat(qa + " ");
}
System.out.println("head " + asd);//stampo contenuto dell' head
row = 1;
}//fine if
else {
Double[] values = new Double[numberOfNumericColumns];
int z = 0;
geneid = st.nextToken();
while (st.hasMoreTokens()) {
String app = st.nextToken();
values[z] = Double.valueOf(app);
z++;
}
r = new Riga(geneid, values); //crei l'oggetto riga
System.out.println("riga");
System.out.println(r.getgeneid());
values = r.getvalues();
for (int e = 0; e <= values.length - 1; e++) {
System.out.println(values[e]);
}
insRighe(r); //aggiungi
}
row++;
}
while (i < intest.length) {
byte[] bytesnew = intest.getBytes();
//temp.addAll(bytesnew);
//memorizza in byte un elemento del vettore alla volta
for (byte b : bytesnew)
temp.add(new Byte(b)); //provare Byte
//temp.addElement(intest.getBytes());
temp.addElement(Byte.valueOf(middlerow));
i++;
}
temp.addElement(Byte.valueOf(endrow));
System.out.println("Intestazione convertita in byte");
for (int l = 0; l < rows.size(); l++) {
r = (Riga) rows.get(l);
g = r.getgeneid();
//temp.addElement(g.getBytes());
byte[] byte2 = g.getBytes();
for (byte c : byte2)
temp.add(new Byte(c));
temp.addElement(Byte.valueOf(middlerow));
val = r.getvalues();
byte[] tempByte1;
for (int e = 0; e <= val.length - 1; e++) {
//Returns a string representation of the double argument.
tempByte1 = Double.toString(val[e]).getBytes();
for (int j = 0; j < tempByte1.length; j++) {
temp.addElement(Byte.valueOf(tempByte1[j]));
}
temp.addElement(Byte.valueOf(middlerow));
}
temp.addElement(Byte.valueOf(endrow));
}
data = new byte[temp.size()];
//OutputStream os=new OutputStream(file);
for (int t = 0; t < temp.size() ; t++) {
data[t] = (((Byte) temp.elementAt(t)).byteValue());
}
Test t=new Test();
t.addtoblob(data);
return "success";
}
}
and before terminating this bean call the method addtoblob of class
Test...
import java.io.IOException;
import java.io.StringReader;
import java.util.Vector;
import java.sql.*;
public class Test {
public void addtoblob(byte[] datanew) {
Database dbs = new Database("nomeDB", "root", "shevagol");
if (!dbs.connetti()) {
System.out.println("Errore durante la connessione.");
System.out.println(dbs.getErrore());
System.exit(0);
}
try {
Connection db = dbs.getConnection();
PreparedStatement pst = db
.prepareStatement("INSERT INTO tbl(Nome,Data) VALUES (?,?)");
//imposto i valori
pst.setString(1, "ciao21");
pst.setBytes(2, datanew);
pst.executeUpdate();
pst.close();
} catch (SQLException sqlex) {
sqlex.printStackTrace();
}
// Stampiamo i risultati:
dbs.disconnetti();
}
Is here the error?
My application don't gives me error,but don't insert nothing in the
table,while my same java application do it well...can someone help me?
Thanks