Ciao siamo un gruppo di programmatori java...
dobbiamo creare una rubrica.....
siamo partiti creando un database...fin qui tutto bene...
abbiamo creato la classe per inserire i dati:
spero si riesca a capire qualcosa,
package wa;
import java.sql.*;
import java.util.*;
import java.text.*;
import java.io.*;
class Insert
{
String tabella=null, nome_ditta="";
public Insert(String t)
{
tabella=t;
}
public void Inserisci(String[] Arg) // throws Exception
{
try
{
DbConnection dbConnection = new DbConnection();
java.sql.Connection con = dbConnection.getConn();
java.sql.Statement stmt = con.createStatement();
//System.out.println("connesione " + con );
String query="insert into ",query_TMP="";
query=query+tabella;
int val=0;
if(tabella=="tb_ditte")
{
query=query + " (nome, tel_ufficio, fax, cellulare, indirizzo, email, note, tipo,sito) values('";
for(int i=0;i< Arg.length;i++)
{
if(8==i)
{
query_TMP=query_TMP + Arg[i] + "'";
val=1;
break;//i=11;
}
else{
query_TMP=query_TMP + Arg[i] + "','";
nome_ditta= Arg[0];
}
}
}
if(tabella=="tb_contatti")
{
query=query + "(nome, tel_ufficio, fax, cellulare, indirizzo, email, note, IdDitta) values ('";
for(int i=0;i< Arg.length;i++)
{
if(7==i)
{
query_TMP=query_TMP + Arg[i];
break;//i=11;
}
else if(6==i)
query_TMP=query_TMP + Arg[i] + "',";
else
query_TMP=query_TMP + Arg[i] + "','";
}
}
if(tabella=="tb_collaboratori")
{ query=query + "(nome, tel_ufficio, tel_casa, cellulare, indirizzo, email, cognome,note) values('";
for(int i=0;i< Arg.length;i++)
{
if(7==i)
{
query_TMP=query_TMP + Arg[i] + "'";
break;//i=11;
}
else
query_TMP=query_TMP + Arg[i] + "','
}
}
query=query + query_TMP + ")";
/*for(int qq=0; qq < Arg.length; qq++)
System.out.println("connesione " + Arg[qq]);
System.out.println("sql " + query + " \n Arg.length " + Arg.length );
*/
stmt.executeUpdate(query);
stmt.close();
con.close();
if(val==1)
Crea_contatti(nome_ditta);
}
catch (Exception e){
System.out.println("error mio ");}
}
private void Crea_contatti(String n_Ditta )
{
int id=0;
try
{
DbConnection dbConnection1 = new DbConnection();
java.sql.Connection con1 = dbConnection1.getConn();
java.sql.Statement stmt1 = con1.createStatement();
//System.out.println("connesione " + con );
String query="select id from tb_ditte where nome like'"+ n_Ditta + "'";
id=Integer.valueOf(n_Ditta).intValue();
stmt1.executeUpdate(query);
stmt1.close();
con1.close();
DbConnection dbConnection2 = new DbConnection();
java.sql.Connection con2 = dbConnection2.getConn();
java.sql.Statement stmt2 = con2.createStatement();
//System.out.println("connesione " + con );
for(int t=0;t<6;t++)
{
if(tabella=="tb_contatti")
{
query=query + "(nome, tel_ufficio, fax, cellulare, indirizzo, email, note, IdDitta) values ('','','','','','','', " + id + ")";
stmt2.executeUpdate(query);
}
}
stmt2.close();
con2.close();
}
catch (Exception e){
System.out.println("error mio ");}
}
}