tag:blogger.com,1999:blog-50292389932454862172023-11-15T18:34:23.404+01:00MiniguidaUnknownnoreply@blogger.comBlogger27125tag:blogger.com,1999:blog-5029238993245486217.post-55563886225236173222009-07-30T15:57:00.003+01:002009-07-30T16:09:18.884+01:00Configurazione di Apache Tomcat 6.x* Incollare i sorgenti dell'applicazione Web in una cartella, ad esempio applicazione, e spostarla nella cartella webapps di Tomcat<br /><br />* (facoltativo) Aggiungere le seguenti righe a tomcat-users.xml (in conf)<br /><blockquote><role rolename="admin"/><br /><role rolename="manager"/><br /><user username="admin" password="admin" roles="admin,manager"/></blockquote><br /><br />in modo da poter accedere al tomcat manager con l'utenza admin<br /><br />* Nel file servers.xml (in conf) aggiungiamo la nostra applicazione:<br /><Host appBase="C:\Tools\apache-tomcat-6.0.20\webapps\applicazione" name="applicazione"<br /> unpackWARs="false" <br /> xmlValidation="false" <br /> xmlNamespaceAware="false" <br /> autoDeploy="false" <br /> deployOnStartup="false" <br /> liveDeploy="false"><br /> <Logger className="org.apache.catalina.logger.FileLogger" suffix=".txt" prefix="app.log." timestamp="true"/><br /> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="c:/LOGS" prefix="amadeus_" suffix=".log" pattern="common" resolveHosts="false"/><br /> <Context docBase="/" path="" reloadable="true" /><br /> </Host><br /><br />* Ora modifichiamo il DNS per inserire la nostra Webapp: modifichiamo il file c:\windows\system32\drivers\etc\hosts inserendo la riga<br /><br />127.0.0.1 applicazione.app.it<br /><br />* Avviamo tomcat da riga di comando: spostiamoci nella cartella bin e digitiamo startup.bat (se siamo in ambiente Windows)<br /><br />* Richiamiamo la nostra applicazione nel browser digitando http://applicazione.app.it:8080flaviohttp://www.blogger.com/profile/11659260459682203620noreply@blogger.com0tag:blogger.com,1999:blog-5029238993245486217.post-69350892799549887872009-05-05T16:13:00.003+01:002009-05-05T16:30:12.029+01:00Gestione di un acquisto PayPalCreare innanzitutto da Sandbox (<a href="http://developer.paypal.com">http://developer.paypal.com</a>) un account Business ed uno Personal (personalmente ho preferito creare manualmente due utenti italiani, visto che nei preimpostati al momento non è possibile farlo), attivare email ed associare una carta di credito fittizia oppure un conto. Nell'utente Business, andare su profile->website payment preferences, attivare Auto-Return, inserire l'indirizzo di ritorno PDT (es.: http://pdt.php) e attivare Payment Data Transfer e segnarsi l'id.<br />Poi su profile -> Instant Payment Notification abilitare l'opzione ed inserire l'url che gestirà l'IPN (es: http://...../ipn.php).<br />Poi andare su merchant services e creare un bottone di acquisto e copiarne ed incollarne il codice in una pagina Web (es: payWithPayPal.php), aggiungendo se necessario un campo hidden chiamato "custom" e valorizzato con un valore di cui si vuole tenere traccia (max 255 caratteri). Questo è necessario se voglio per esempio salvare su database l'andamento della transazione se andata a buon fine ed associarla all'utente salvato in sessione: essendo fatte su ipn.php solo chiamate asincrone, l'istruzione $_SESSION non funziona come ci si aspetterebbe. Passandogli invece la variabile custom, posso riceverla comunque in ipn.php e farci tutte le operazioni che desidero.<br />Ecco i codici di esempio delle due pagine:<br /><br />payWithPayPal.php<br /><br /><form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post"><br /><input type="hidden" name="cmd" value="_s-xclick"><br /><input type="hidden" name="custom" value="variabileCustom"><br /><input type="hidden" name="hosted_button_id" value="37237"><br /><input type="image" src="https://www.sandbox.paypal.com/it_IT/IT/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - Il sistema di pagamento online più facile e sicuro!"><br /><img alt="" border="0" src="https://www.sandbox.paypal.com/it_IT/i/scr/pixel.gif" width="1" height="1" /><br /></form><br /><br /><br /><br />ipn.php<br /><br /><?php<br /><br />// read the post from PayPal system and add 'cmd'<br />$req = 'cmd=_notify-validate';<br />foreach ($_POST as $key => $value) {<br /> $value = urlencode(stripslashes($value));<br /> $req .= "&$key=$value";<br />}<br /><br /> <br />// post back to PayPal system to validate<br />$header = "POST /cgi-bin/webscr HTTP/1.0\r\n";<br />$header .= "Content-Type: application/x-www-form-urlencoded\r\n";<br />$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";<br /><br />$sandbox = isset($_POST['test_ipn']) ? true : false;<br /><br />if ($sandbox) {<br /> $fp = fsockopen ('www.sandbox.paypal.com', 80, $errno, $errstr, 30);<br />} else {<br /> $fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);<br />}<br /><br />// assign posted variables to local variables<br />$custom = $_POST['custom'];<br /><br />if (!$fp) {<br /> // HTTP ERROR<br />} else {<br /> fputs ($fp, $header . $req);<br /> while (!feof($fp)) {<br /> $res = fgets ($fp, 1024);<br /> if (strcmp ($res, "VERIFIED") == 0) {<br /> <br /> <br /> if(isset($_POST['payment_status'])){<br /> if ($_POST['payment_status']=="Completed"){<br /> //mettere qui la logica di inserimento di dati nel db<br /> }<br /> }<br /> <br /> }<br /> }<br /> fclose($fp);<br />}<br /><br />?><br /><br /><br /><br /><br />infine, ecco il codice della pagina se si vuole utilizzare pdt.php:<br /><br /><?php<br /><br />$tx = $_GET['tx'];<br /><br />/*<br />Probabilmente è sufficiente usare PDT: qui la pagina capisce che proviene da paypal e quindi posso salvare<br />nel DB l'abbonamento che ha scelto l'utente<br />*/<br />/*<br />$refe=$_SERVER['HTTP_REFERER'];//Estraggo la pagina di provenienza del navigatore<br />$ip=$_SERVER['REMOTE_ADDR'];//Estraggo l'IP del navigatore<br />*/<br />?><br />grazie per aver effettuato il pagamento. La transazione è stata completata e una ricevuta dell'acquisto è stata inviata al tuo indirizzo email. Per visualizzare i dettagli sulla transazione effettua l'accesso al tuo conto dall'indirizzo www.sandbox.paypal.com/it.<br /><br /><br /><form method="POST" action="https://www.sandbox.paypal.com/cgi-bin/webscr"><br /> cmd:<input type="text" name="cmd" value="_notify-synch"><br /> <br/><br /> ID transazione: <input type="text" name="tx" value="">"><br /> <br/><br /> Token identità (quella che imposto attivando PDT sul sito del venditore): <input type="text" name="at" value="[valore token]"><br /> <br/><br /> <input type="submit" value="PDT"><br /></form>flaviohttp://www.blogger.com/profile/11659260459682203620noreply@blogger.com0tag:blogger.com,1999:blog-5029238993245486217.post-18735528099438001282009-04-10T14:35:00.001+01:002009-04-10T14:37:44.757+01:00Autenticazione su LDAP tramite Active Directory con richiesta parametriimport java.io.BufferedReader;<br />import java.io.InputStreamReader;<br />import java.util.Hashtable;<br /><br />import javax.naming.Context;<br />import javax.naming.NamingEnumeration;<br />import javax.naming.NamingException;<br />import javax.naming.directory.Attribute;<br />import javax.naming.directory.Attributes;<br />import javax.naming.directory.SearchControls;<br />import javax.naming.directory.SearchResult;<br />import javax.naming.ldap.InitialLdapContext;<br />import javax.naming.ldap.LdapContext;<br />public class LDAPTest<br />{<br /> static class LDAP<br /> {<br /> static String ATTRIBUTE_FOR_USER = "sAMAccountName";<br /> @SuppressWarnings("unchecked")<br /> public Attributes authenticateUser(String username, String password, String _domain, String host, String dn)<br /> {<br /> String returnedAtts[] ={ "sn", "givenName", "mail" , "company" , "department" };<br /> String searchFilter = "(&(objectClass=user)(" + ATTRIBUTE_FOR_USER + "=" + username + "))";<br /> //Create the search controls<br /> SearchControls searchCtls = new SearchControls();<br /> searchCtls.setReturningAttributes(returnedAtts);<br /> //Specify the search scope<br /> searchCtls.setSearchScope(SearchControls.SUBTREE_SCOPE);<br /> String searchBase = dn;<br /> Hashtable environment = new Hashtable();<br /> environment.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");<br /> //Using starndard Port, check your instalation<br /> environment.put(Context.PROVIDER_URL, "ldap://" + host + ":389");<br /> environment.put(Context.SECURITY_AUTHENTICATION, "simple");<br /> environment.put(Context.SECURITY_PRINCIPAL, username + "@" + _domain);<br /> environment.put(Context.SECURITY_CREDENTIALS, password);<br /> LdapContext ctxGC = null;<br /> try<br /> {<br /> ctxGC = new InitialLdapContext(environment, null);<br /> // Search for objects in the GC using the filter<br /> NamingEnumeration answer = ctxGC.search(searchBase, searchFilter, searchCtls);<br /> while (answer.hasMoreElements())<br /> {<br /> SearchResult sr = (SearchResult)answer.next();<br /> Attributes attrs = sr.getAttributes();<br /> if (attrs != null)<br /> {<br /> return attrs;<br /> }<br /> }<br /> }<br /> catch (NamingException e)<br /> {<br /> System.out.println("Just reporting error");<br /> e.printStackTrace();<br /> }<br /> return null;<br /> }<br /> }<br /> public static void main(String[] args) throws Exception<br /> {<br /> <br /> LDAP ldap = new LDAP();<br /> <br /> String username = "user";<br /> String password = "pwd";<br /><br /> <br /> Attributes att = ldap.authenticateUser(username, password, "dominio.estensione", "ip_addr", "DC=dominio,DC=estensione");<br /> if (att == null)<br /> {<br /> System.out.println("Sorry your use is invalid or password incorrect");<br /> }<br /> else<br /> {<br /> String s = att.get("department").toString();<br /> System.out.println("DEPARTMENT=" + s);<br /> <br /> NamingEnumeration<? extends Attribute> all = att.getAll();<br /> int i = 1;<br /> while(all.hasMore()){<br /> System.out.println("ATTR "+i+" "+all.next().toString());<br /> i++;<br /> }<br /> <br /> }<br /> }<br />}flaviohttp://www.blogger.com/profile/11659260459682203620noreply@blogger.com0tag:blogger.com,1999:blog-5029238993245486217.post-81346329845106010452009-04-10T10:17:00.003+01:002009-04-10T10:22:50.448+01:00Autenticazione su LDAP tramite Active Directoryimport java.util.Hashtable;<br /><br />import javax.naming.Context;<br />import javax.naming.NamingEnumeration;<br />import javax.naming.NamingException;<br />import javax.naming.directory.Attributes;<br />import javax.naming.directory.DirContext;<br />import javax.naming.directory.InitialDirContext;<br /><br />Hashtable env= new Hashtable(11);<br />env.put(Context.SECURITY_PRINCIPAL,"CN=kiran,OU=LinkedgeOU,DC=LINKEDGEDOMAIN"); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");<br />env.put(Context.PROVIDER_URL, "ldap://<url>:389");<br />env.put(Context.SECURITY_AUTHENTICATION, "simple");<br />//username<br /><br />env.put(Context.SECURITY_PRINCIPAL, <username@dominio>);<br />//password<br />env.put(Context.SECURITY_CREDENTIALS, password);<br /><br />try {<br /> DirContext ctx = new InitialDirContext(env);<br /> String[] sAttrIDs = new String[2];<br /> Attributes attr = ctx.getAttributes("");<br /> NamingEnumeration<string> ids = attr.getIDs();<br /> }<br /> catch(NamingException e){<br /> System.err.println("Problem getting attribute: " + e);<br /> }</string></username@dominio></url>flaviohttp://www.blogger.com/profile/11659260459682203620noreply@blogger.com0tag:blogger.com,1999:blog-5029238993245486217.post-12389317740657891642009-04-10T09:47:00.005+01:002009-04-10T10:00:48.206+01:00Configurazione log4j per tomcatScaricare il jar di log4j dal sito di Apache e includerlo nella webapp.<br /><br />Scrivere il file di configurazione log4.properties, del tipo:<br /><br />#LOGGER<br />log4j.rootCategory=DEBUG, APPENDER_CONSOLE, APPENDER_FILE<br /><br />#APPENDER_OUT<br />log4j.appender.APPENDER_CONSOLE=org.apache.log4j.ConsoleAppender<br />log4j.appender.APPENDER_CONSOLE.layout=org.apache.log4j.PatternLayout<br />log4j.appender.APPENDER_CONSOLE.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n<br /><br />#APPENDER_FILE<br />log4j.appender.APPENDER_FILE=org.apache.log4j.RollingFileAppender<br />log4j.appender.APPENDER_FILE.File=c:/mioLog.log<br />log4j.appender.APPENDER_FILE.MaxFileSize=500KB<br />log4j.appender.APPENDER_FILE.MaxBackupIndex=10<br />log4j.appender.APPENDER_FILE.layout=org.apache.log4j.PatternLayout<br />log4j.appender.APPENDER_FILE.layout.ConversionPattern=%p %t %c - %m%n<br /><br /><br />in cui imposto i console e file appender per il livello di debug.<br /><br />In <a href="http://logging.apache.org/log4j/1.2/manual.html">http://logging.apache.org/log4j/1.2/manual.html</a> è descritta la seguente configurazione<br />Imposto la servlet di inizializzazione di log4j:<br /><br />package it.flavio.ldap;<br /><br />import org.apache.log4j.PropertyConfigurator;<br />import javax.servlet.http.HttpServlet;<br />import javax.servlet.http.HttpServletRequest;<br />import javax.servlet.http.HttpServletResponse;<br /><br />public class Log4jInit extends HttpServlet {<br /><br />public<br />void init() {<br /> String prefix = getServletContext().getRealPath("/");<br /> String file = getInitParameter("log4j-init-file");<br /> // if the log4j-init-file is not set, then no point in trying<br /> if(file != null) {<br /> //PropertyConfigurator.configure(prefix+file);<br /> PropertyConfigurator.configure("c:\\log4j.properties");<br /> }<br />}<br /><br />public<br />void doGet(HttpServletRequest req, HttpServletResponse res) {<br />}<br />}<br /><br /><br /><br />e quindi aggiungo a web.xml il seguente mapping per fare eseguire questa servlet all'inizio dell'applicazione:<br /><br /><br /><><br /> <> log4j-init< / servlet-name ><br /> <>it.flavio.ldap< /servlet-class ><br /><br /> <><br /> <>log4j-init-file< /param-name ><br /> <>WEB-INF/classes/log4j.lcf< /param-value ><br /> < /init-param ><br /><br /> <>1< /load-on-startup ><br /> < /servlet ><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;font-family:Verdana;font-size:13;" ><pre></pre></span><br /><br /><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;font-family:Verdana;font-size:13;" ><pre> <servlet></servlet><span style="font-size:100%;"><br />Ora le impostazioni per il logging sono configurate, per generare i file di log è sufficiente aggiungere la riga:<br /><br />Logger log = Logger.getLogger(Log4jInit.class);<br /><br />nelle classi in cui vogliamo fare logging coi metodi log.debug, log.error ecc..<br /><br /></span><br /></pre></span>flaviohttp://www.blogger.com/profile/11659260459682203620noreply@blogger.com0tag:blogger.com,1999:blog-5029238993245486217.post-1535040231955782212009-04-09T14:40:00.006+01:002009-04-09T16:22:54.367+01:00JDBC SQL Server 2000Per gestire JDBC con le librerie della Microsoft<br /><br />Aggiungere al progetto i jar reperibili sul sito di microsoft:<br />msbase.jar<br />mssqlserver.jar<br />msutil.jar<br /><br />try{<br /> // caricamento della classe del driver<br /> Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");<br /> } catch(Exception E){<br /> System.out.println(E.toString());<br /> }<br /> try{<br /> Connection MyConn = DriverManager.getConnection("jdbc:microsoft:sqlserver://db_address:1433;databaseName=db_name;User=username;Password=password");<br /> } catch(Exception E){<br />System.out.println(E.toString());<br /> }<br /><br /><br /><br /><br />Per gestire invece con JTDS<br />Driver: net.sourceforge.jtds.jdbc.Driver<br />URL: jdbc:jtds:<server_type>://<server>[:<port>][/<database>][;<property>=<value>[;...]]<br /><br />I jar necessari si trovano su sourceforge (<a href="http://jtds.sourceforge.net/">http://jtds.sourceforge.net/</a> -> download)<br />Scompattare l'archivio, il jar si trova nella root e si chiama jtds<version>.jar<br />Ho dovuto inoltre copiare il file <span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;font-family:verdana;font-size:13;" >\x86\SSO\ntlmauth.dll in [...]\jdk\jre\bin<br /><br /><br /></span></version></value></property></database></port></server></server_type>flaviohttp://www.blogger.com/profile/11659260459682203620noreply@blogger.com0tag:blogger.com,1999:blog-5029238993245486217.post-43557165770305405432009-04-03T08:20:00.008+01:002009-04-03T08:33:18.726+01:00Relazione many-to-many con attributi con HibernateMappare una molti-a-molti semplice con Hibernate usando le annotations è un'operazione piuttosto immediata, le cose si complicano quando si vanno ad aggiungere proprietà aggiuntive a questa relazione. Seguendo il manuale "Java Persistence With Hibernate", ecco l'esempio della mappatura di una relazione molti-a-molti con attributi, realizzata esplicitando la join table messa in relazione uno-a-molti con entrambe le tabelle interessate. Le tabelle in questione sono "Utente" e "Movie", in relazione molti-a-molti e mappate dalla join table utente_movie.<br /><br />Ecco il codice delle classi con cui è stata realizzata la mappatura:<br /><br /><br /><span style="font-weight: bold;">UTENTE</span><br /><br />package it.flavio.moltiamolti.model;<br /><br />import java.io.Serializable;<br />import java.util.Collections;<br />import java.util.Map;<br />import java.util.Set;<br />import java.util.WeakHashMap;<br /><br />import javax.persistence.Column;<br />import javax.persistence.Entity;<br />import javax.persistence.GeneratedValue;<br />import javax.persistence.GenerationType;<br />import javax.persistence.Id;<br />import javax.persistence.OneToMany;<br />import javax.persistence.Table;<br />import javax.persistence.Transient;<br /><br />import org.springmodules.validation.bean.conf.loader.annotation.handler.Length;<br /><br /><br />/**<br />* Object mapping for hibernate-handled table: movie.<br />* @author autogenerated<br />*/<br /><br />@Entity<br />@Table(name = "utente", catalog = "moltiamolti")<br />public class Utente implements Cloneable, Serializable {<br /><br /> /** Serial Version UID. */<br /> private static final long serialVersionUID = -559009206L;<br /><br /> /** Use a WeakHashMap so entries will be garbage collected once all entities<br /> referring to a saved hash are garbage collected themselves. */<br /> private static final Map<serializable,> SAVED_HASHES =<br /> Collections.synchronizedMap(new WeakHashMap<serializable,>());<br /><br /> /** hashCode temporary storage. */<br /> private volatile Integer hashCode;<br /> private Set<utentetomovie> utenteToMovies;<br /><br /> /** Field mapping. */<br /> private String name;<br /> /** Field mapping. */<br /> private Long id = 0L; // init for hibernate bug workaround<br /><br /> /**<br /> * Default constructor, mainly for hibernate use.<br /> */<br /> public Utente() {<br /> // Default constructor<br /> }<br /><br /> /** Constructor taking a given ID.<br /> * @param id to set<br /> */<br /> public Utente(Long id) {<br /> this.id = id;<br /> }<br /><br /><br /> /** Return the type of this class. Useful for when dealing with proxies.<br /> * @return Defining class.<br /> */<br /> @Transient<br /> public Class getClassType() {<br /> return Utente.class;<br /> }<br /><br /><br /> /**<br /> * Return the value associated with the column: duration.<br /> * @return A String object (this.duration)<br /> */<br /> @Length(max=45)<br /> @Column( length = 45 )<br /> public String getName() {<br /> return this.name;<br /> <br /> }<br /><br /><br /> /**<br /> * Set the value related to the column: duration.<br /> * @param duration the duration value you wish to set<br /> */<br /> public void setName(final String name) {<br /> this.name = name;<br /> }<br /><br /> /**<br /> * Return the value associated with the column: id.<br /> * @return A Integer object (this.id)<br /> */<br /> @Id<br /> @GeneratedValue(strategy = GenerationType.AUTO)<br /> @Column( name = "utente" )<br /> public Long getId() {<br /> return this.id;<br /> <br /> }<br /><br /><br /><br /> /**<br /> * Set the value related to the column: id.<br /> * @param id the id value you wish to set<br /> */<br /> public void setId(final Long id) {<br /> // If we've just been persisted and hashCode has been<br /> // returned then make sure other entities with this<br /> // ID return the already returned hash code<br /> if ( (this.id == null || this.id == 0) &&<br /> (id != null) &&<br /> (this.hashCode != null) ) {<br /> SAVED_HASHES.put( id, this.hashCode );<br /> }<br /> this.id = id;<br /> }<br /><br /><br /> @Column( nullable = false )<br /> @OneToMany( mappedBy = "utente" )<br /> public Set<utentetomovie> getUtenteToMovies() {<br /> return utenteToMovies;<br /> }<br /><br /> public void setUtenteToMovies(Set<utentetomovie> utenteToMovies) {<br /> this.utenteToMovies = utenteToMovies;<br /> }<br /><br /><br /><br />/**<br /> * Deep copy.<br /> * @return cloned object<br /> * @throws CloneNotSupportedException on error<br /> */<br /> @Override<br /> public Utente clone() throws CloneNotSupportedException {<br /> super.clone(); // keep hierarchy<br /> final Utente copy = new Utente();<br /><br /> <br /> copy.setName(this.getName());<br /> copy.setId(this.getId());<br /> <br /> return copy;<br /> }<br /><br /><br /> /** Provides toString implementation.<br /> * @see java.lang.Object#toString()<br /> * @return String representation of this class.<br /> */<br /> @Override<br /> public String toString() {<br /> StringBuffer sb = new StringBuffer();<br /> <br /> sb.append("duration: " + this.getName() + ", ");<br /> sb.append("id: " + this.getId() + ", ");<br /> <br /> return sb.toString(); <br /> }<br /><br /> @Override<br /> public int hashCode() {<br /> final int prime = 31;<br /> int result = 1;<br /> <br /> <br /> result = prime * result<br /> + ((name == null) ? 0 : name.hashCode());<br /> <br /> result = prime * result<br /> + ((hashCode == null) ? 0 : hashCode.hashCode());<br /> result = prime * result + ((id == null) ? 0 : id.hashCode());<br /> <br /> return result;<br /> }<br /><br /> @Override<br /> public boolean equals(Object obj) {<br /> if (this == obj)<br /> return true;<br /> if (obj == null)<br /> return false;<br /> if (getClass() != obj.getClass())<br /> return false;<br /> Utente other = (Utente) obj;<br /> <br /> if (name == null) {<br /> if (other.name != null)<br /> return false;<br /> } else if (!name.equals(other.name))<br /> return false;<br /> <br /> <br /> if (hashCode == null) {<br /> if (other.hashCode != null)<br /> return false;<br /> } else if (!hashCode.equals(other.hashCode))<br /> return false;<br /> if (id == null) {<br /> if (other.id != null)<br /> return false;<br /> } else if (!id.equals(other.id))<br /> return false;<br /> <br /> return true;<br /> }<br /><br />}<br /><br /><br /><br /><br /><br /><span style="font-weight: bold;">MOVIE</span><br /><br />package it.flavio.moltiamolti.model;<br /><br />import java.io.Serializable;<br />import java.util.Collections;<br />import java.util.Map;<br />import java.util.Set;<br />import java.util.WeakHashMap;<br /><br />import javax.persistence.Column;<br />import javax.persistence.Entity;<br />import javax.persistence.GeneratedValue;<br />import javax.persistence.GenerationType;<br />import javax.persistence.Id;<br />import javax.persistence.OneToMany;<br />import javax.persistence.Table;<br />import javax.persistence.Transient;<br /><br />import org.springmodules.validation.bean.conf.loader.annotation.handler.Length;<br /><br /><br />/**<br />* Object mapping for hibernate-handled table: movie.<br />* @author autogenerated<br />*/<br /><br />@Entity<br />@Table(name = "movie", catalog = "moltiamolti")<br />public class Movie implements Cloneable, Serializable {<br /><br /> /** Serial Version UID. */<br /> private static final long serialVersionUID = -559009206L;<br /><br /> /** Use a WeakHashMap so entries will be garbage collected once all entities<br /> referring to a saved hash are garbage collected themselves. */<br /> private static final Map<serializable,> SAVED_HASHES =<br /> Collections.synchronizedMap(new WeakHashMap<serializable,>());<br /><br /> /** hashCode temporary storage. */<br /> private volatile Integer hashCode;<br /> private Set<utentetomovie> utenteToMovies;<br /><br /><br /><br /> /** Field mapping. */<br /> private String duration;<br /> /** Field mapping. */<br /> private Long id = 0L; // init for hibernate bug workaround<br /><br /> /**<br /> * Default constructor, mainly for hibernate use.<br /> */<br /> public Movie() {<br /> // Default constructor<br /> }<br /><br /> /** Constructor taking a given ID.<br /> * @param id to set<br /> */<br /> public Movie(Long id) {<br /> this.id = id;<br /> }<br /><br /><br /> /** Return the type of this class. Useful for when dealing with proxies.<br /> * @return Defining class.<br /> */<br /> @Transient<br /> public Class getClassType() {<br /> return Movie.class;<br /> }<br /><br /><br /><br /><br /><br /><br /><br /> /**<br /> * Return the value associated with the column: duration.<br /> * @return A String object (this.duration)<br /> */<br /> @Length(max=45)<br /> @Column( length = 45 )<br /> public String getDuration() {<br /> return this.duration;<br /> <br /> }<br /><br /><br /><br /> /**<br /> * Set the value related to the column: duration.<br /> * @param duration the duration value you wish to set<br /> */<br /> public void setDuration(final String duration) {<br /> this.duration = duration;<br /> }<br /><br /> /**<br /> * Return the value associated with the column: id.<br /> * @return A Integer object (this.id)<br /> */<br /> @Id<br /> @GeneratedValue(strategy = GenerationType.AUTO)<br /> @Column( name = "movie" )<br /> public Long getId() {<br /> return this.id;<br /> <br /> }<br /><br /><br /><br /> /**<br /> * Set the value related to the column: id.<br /> * @param id the id value you wish to set<br /> */<br /> public void setId(final Long id) {<br /> // If we've just been persisted and hashCode has been<br /> // returned then make sure other entities with this<br /> // ID return the already returned hash code<br /> if ( (this.id == null || this.id == 0) &&<br /> (id != null) &&<br /> (this.hashCode != null) ) {<br /> SAVED_HASHES.put( id, this.hashCode );<br /> }<br /> this.id = id;<br /> }<br /><br /><br /><br /> /**<br /> * Return the value associated with the column: itemOrder.<br /> * @return A Set<ItemOrder> object (this.itemOrder)<br /> */<br /> @Column( nullable = false )<br /> @OneToMany( mappedBy = "movie" )<br /> public Set<utentetomovie> getUtenteToMovies() {<br /> return utenteToMovies;<br /> }<br /><br /> public void setUtenteToMovies(Set<utentetomovie> utenteToMovies) {<br /> this.utenteToMovies = utenteToMovies;<br /> }<br /><br /><br /><br /><br /><br /><br /><br />/**<br /> * Deep copy.<br /> * @return cloned object<br /> * @throws CloneNotSupportedException on error<br /> */<br /> @Override<br /> public Movie clone() throws CloneNotSupportedException {<br /> super.clone(); // keep hierarchy<br /> final Movie copy = new Movie();<br /><br /> <br /> copy.setDuration(this.getDuration());<br /> copy.setId(this.getId());<br /> <br /> return copy;<br /> }<br /><br /><br /> /** Provides toString implementation.<br /> * @see java.lang.Object#toString()<br /> * @return String representation of this class.<br /> */<br /> @Override<br /> public String toString() {<br /> StringBuffer sb = new StringBuffer();<br /> <br /> sb.append("duration: " + this.getDuration() + ", ");<br /> sb.append("id: " + this.getId() + ", ");<br /> <br /> return sb.toString(); <br /> }<br /><br /> @Override<br /> public int hashCode() {<br /> final int prime = 31;<br /> int result = 1;<br /> <br /> <br /> result = prime * result<br /> + ((duration == null) ? 0 : duration.hashCode());<br /> <br /> result = prime * result<br /> + ((hashCode == null) ? 0 : hashCode.hashCode());<br /> result = prime * result + ((id == null) ? 0 : id.hashCode());<br /> <br /> return result;<br /> }<br /><br /> @Override<br /> public boolean equals(Object obj) {<br /> if (this == obj)<br /> return true;<br /> if (obj == null)<br /> return false;<br /> if (getClass() != obj.getClass())<br /> return false;<br /> Movie other = (Movie) obj;<br /> <br /> if (duration == null) {<br /> if (other.duration != null)<br /> return false;<br /> } else if (!duration.equals(other.duration))<br /> return false;<br /> <br /> <br /> if (hashCode == null) {<br /> if (other.hashCode != null)<br /> return false;<br /> } else if (!hashCode.equals(other.hashCode))<br /> return false;<br /> if (id == null) {<br /> if (other.id != null)<br /> return false;<br /> } else if (!id.equals(other.id))<br /> return false;<br /> <br /> return true;<br /> }<br /><br /><br />}<br /><br /><br /><br /><br /><span style="font-weight: bold;">UTENTETOMOVIE</span><br /><br /><br />package it.flavio.moltiamolti.model;<br /><br />import java.io.Serializable;<br /><br />import javax.persistence.Column;<br />import javax.persistence.Embeddable;<br />import javax.persistence.EmbeddedId;<br />import javax.persistence.Entity;<br />import javax.persistence.JoinColumn;<br />import javax.persistence.ManyToOne;<br />import javax.persistence.Table;<br /><br /><br />/**<br />* Object mapping for hibernate-handled table: movie.<br />* @author autogenerated<br />*/<br /><br />@Entity<br />@Table(name = "utente_movie", catalog = "moltiamolti")<br />public class UtenteToMovie implements Cloneable, Serializable {<br /><br /> @Embeddable<br /> public static class Id implements Serializable {<br /> @Column(name = "movie_id")<br /> private Long movieId;<br /> <br /> @Column(name = "utente_id")<br /> private Long utenteId;<br /> <br /> public Id() {}<br /> public Id(Long movieId, Long utenteId) {<br /> this.movieId = movieId;<br /> this.utenteId = utenteId;<br /> }<br /> public boolean equals(Object o) {<br /> if (o != null && o instanceof Id) {<br /> Id that = (Id)o;<br /> return this.movieId.equals(that.movieId) &&<br /> this.utenteId.equals(that.utenteId);<br /> } else {<br /> return false;<br /> }<br /> }<br /> public int hashCode() {<br /> return movieId.hashCode() + utenteId.hashCode();<br /> }<br /> }<br /><br /><br /> @EmbeddedId<br /> private Id id = new Id();<br /> <br /> @ManyToOne<br /> @JoinColumn(name="utente_id",<br /> insertable = false,<br /> updatable = false)<br /> private Utente utente;<br /><br /> @ManyToOne<br /> @JoinColumn(name="movie_id",<br /> insertable = false,<br /> updatable = false)<br /> private Movie movie;<br /><br /><br /><br /> private String quantity;<br /> @Column(name = "quantity" , length = 50)<br /> public String getQuantiy(){<br /> return this.quantity;<br /> }<br /><br /> public void setQuantity(String quantity){<br /> this.quantity = quantity;<br /> }<br /><br /><br /><br /> public UtenteToMovie() {}<br /> public UtenteToMovie( Movie movie,<br /> Utente utente) {<br /> // Set fields<br /> //this.username = username;<br /> this.movie = movie;<br /> this.utente = utente;<br /> // Set identifier values<br /> this.id.movieId = movie.getId();<br /> this.id.utenteId = utente.getId();<br /> // Guarantee referential integrity<br /> movie.getUtenteToMovies().add(this);<br /> utente.getUtenteToMovies().add(this);<br /> }<br /><br /><br /><br /><br /> public Id getId() {<br /> return id;<br /> }<br /> public void setId(Id id) {<br /> this.id = id;<br /> }<br /> public Utente getUtente() {<br /> return utente;<br /> }<br /> public void setUtente(Utente utente) {<br /> this.utente = utente;<br /> }<br /> public Movie getMovie() {<br /> return movie;<br /> }<br /> public void setMovie(Movie movie) {<br /> this.movie = movie;<br /> }<br /><br /><br />}</utentetomovie></utentetomovie></utentetomovie></serializable,></serializable,></utentetomovie></utentetomovie></utentetomovie></serializable,></serializable,>flaviohttp://www.blogger.com/profile/11659260459682203620noreply@blogger.com0tag:blogger.com,1999:blog-5029238993245486217.post-37094261978881705972008-11-17T20:29:00.005+01:002008-11-29T16:10:47.914+01:00Problema scheda video SIS M760GX di Acer Aspire 5000 su Ubuntu Intrepid IbexHo avuto un grande problema con i driver della scheda video indicata appena ho installato Ubuntu 8.10: i colori erano completamente sfasati e molti pixel "pulsavano". Senza modificare Xorg.conf, ho risolto aggiungendo la riga:<br /><br />sisfb<br /><br />al file /etc/modules<br /><br />Dopo aver riavviato ed impostato la memoria video condivisa a 64Mb il problema pare risolto.flaviohttp://www.blogger.com/profile/11659260459682203620noreply@blogger.com0tag:blogger.com,1999:blog-5029238993245486217.post-29396690985235563522007-06-12T09:26:00.000+01:002007-06-25T10:23:19.436+01:00Operazioni pianificate UbuntuPer eseguire operazioni pianificate in Ubuntu, procedere col seguente modo.<br />Se non esiste ancora alcuna operazione pianificata, con un editor di testo creare il file <span style="font-weight: bold;">crontab</span> nella cartella <span style="font-weight: bold;">/var/spool/cron/crontabs/</span><br />La riga di comando per pianificare un'operazione ha la seguente struttura:<br /><span style="font-style: italic;"><br />min h giornoMese mese giornoSettimana comando parametri<br /><br /></span><span style="font-style: italic;">min:</span> minuto in cui eseguire l'operazione (0-59)<br /><span style="font-style: italic;">h:</span> ora (0-23)<br /><span style="font-style: italic;">giornoMese:</span> giorno del mese (1-31)<br /><span style="font-style: italic;">mese:</span> mese (1-12)<br /><span style="font-style: italic;">giornoSettimana:</span> giorno della settimana (0-6, con domenica = 0)<br /><span style="font-style: italic;">comando:</span> il comando da eseguire<br /><span style="font-style: italic;">paramteri:</span> eventuali parametri. Questo campo è facoltativo.<br /><br />Se per esempio si vuole pianificare l'esecuzione del file jmail.sh alle 15.58 di ogni giorno, si dovrà inserire nella riga:<br /><br />58 15 * * * ./home/tostao/workspace/javaMail1/jmail.sh<br /><br />(jmail.sh deve essere reso eseguibile tramite il comando chmod. Vedi post "Creazione di uno shell script per eseguire un JAR", tag JAR, Ubuntu).<br />Importante: l'ultima riga del file crontab DEVE esistere ed essere vuota!<br />Per concludere, ora bisogna associare il file crontab creato all'utente di Ubuntu.<br />Per fare ciò, andare nel terminale e digitare:<br /><br /><span style="font-weight: bold;">sudo crontab -u </span><span style="font-style: italic; font-weight: bold;">utente</span><span style="font-weight: bold;"> /var/spool/cron/crontabs/crontab<br /><br /></span>Per verificare che l'operazione è andata a buon fine, digitare <span style="font-weight: bold;">crontab -l</span> per vedere le righe contenute nel nostro file crontab.<br />Per editare tale file, si può lanciare il comando crontab -e , ma personalmente preferisco farlo aprendolo a mano con un editor di testo.<br />Dopo ogni modifica, è necessario riscrivere il comando scritto poco sopra per associare il crontab all'utente.<br /><span style="font-weight: bold;"></span><span style="font-style: italic;"></span>flaviohttp://www.blogger.com/profile/11659260459682203620noreply@blogger.com0tag:blogger.com,1999:blog-5029238993245486217.post-30943734756067037062007-06-11T23:04:00.000+01:002007-06-12T09:26:33.839+01:00Creazione di uno shell script per eseguire un JARUbuntu usa <span style="font-weight: bold;">shell scripting</span>, paragonabile ai file batch (.bat) di Windows ma molto più potente.<br />Per associare uno shell script (in genere salvato come .sh anche se l'estensione non è necessaria), aprire un editor di testo e impostare come prima riga:<br /><span style="font-weight: bold;">#!/bin/bash</span><br />e in seguito le istruzioni desiderate (nel nostro caso: java -jar <span style="font-style: italic;">nomefile</span>.jar)<br />Nella parte <span style="font-style: italic;">nomefile</span>.jar è meglio inserire il <span style="font-weight: bold;">percorso completo</span> del file JAR per essere sempre sicuri di eseguire quel file, in particolare se si sta eseguendo il file .sh da un'applicazione esterna, come ad esempio crontab (strumento per eseguire operazioni pianificate in Ubuntu).<br />Salviamo il nostro file come scriptJAR.sh nella cartella del nostro file .jar<br />Ora bisogna rendere questo file <span style="font-weight: bold;">eseguibile:</span> per fare cioè andare nel terminale, spostarsi nella cartella del nostro scriptJAR.sh e digitare:<br /><span style="font-weight: bold;">sudo chmod +x scriptJAR.sh</span><br />per rendere il nostro script eseguibile: basterà avviarlo per fare avviare il nostro file JAR.<br /><span style="font-weight: bold; color: rgb(0, 0, 153);"><br /></span>flaviohttp://www.blogger.com/profile/11659260459682203620noreply@blogger.com0tag:blogger.com,1999:blog-5029238993245486217.post-82609976972644169752007-06-11T21:49:00.000+01:002007-06-11T23:19:11.432+01:00Esecuzione automatica di un file JARPer fare eseguire automaticamente un file JAR, creare con un qualsiasi editor di testo un file con estensione <span style="font-weight: bold;">.bat</span> contenente il testo:<br />java -jar <em>nomefile</em>.jar<br />e salvarlo nella stessa cartella del file JAR.<br />Viene così creato un file di <span style="font-weight: bold;">batch</span> in grado di eseguire le istruzioni in esso contenute nella riga di comando.<br />Per settare l'operazione pianificata relativa al JAR in questione, in WindowsXP è necessario andare in Pannello di controllo->Operazioni Pianificate->Aggiungi operazione pianificata. Settare via via i parametri che interessano, quando viene richiesta l'applicazione da fare eseguire andare su "Sfoglia..." e selezionare il file .bat creato precedentemente. Fare attenzione all'utente: nel campo "Esegui come:" inserire <strong>NT AUTHORITY\SYSTEM</strong>. In questo modo l'operazione pianificata funzionerà sicuramente visto che è stato inserito l'utente root.flaviohttp://www.blogger.com/profile/11659260459682203620noreply@blogger.com0tag:blogger.com,1999:blog-5029238993245486217.post-10067234651100426592007-06-06T15:52:00.000+01:002007-06-06T15:54:46.928+01:00Report con scelta da casella combinataIn questo modo si apre un report non di tutti i dati ma solo di quelli relativi al campo scelto nella casella combinata.<br /><blockquote> DoCmd.OpenReport "Partite", acPreview, , "Giocatore = " & Chr(34) & Me.CasellaCombinata2 & Chr(34)</blockquote>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-5029238993245486217.post-63391419298257423102007-06-05T23:22:00.000+01:002007-06-05T23:25:08.992+01:00Mandare email da form AccessQuesto è il codice da inserire al click del pulsante:<br /><blockquote>DoCmd.SendObject acSendNoObject, , acFormatXLS, Me.email_recipient, , , "Test Email", , True</blockquote>Dove email.recipient è il contenuto del campo di testo compilato in precedenza.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-5029238993245486217.post-40839813040703355572007-05-30T14:09:00.000+01:002007-05-30T14:12:39.809+01:00Settare variabili d'ambiente<pre>Per non scrivere ogni volta il path a un programma...<br /><blockquote>WINDOWS: set PATH=c:\programmi\java\jdk1.6.0;%PATH%<br />UNIX: export PATH=/opt/jdk1.6.0;$PATH</blockquote></pre>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-5029238993245486217.post-74362136671167873192007-05-15T18:16:00.000+01:002007-05-15T18:20:01.680+01:00Memoria heap per i file .jarPer assegnare a priori una certa quantità di memoria heap da dedicare all'esecuzione di un file jar, è sufficiente aggiungere il parametro -Xmx[memoria da dedicare in Mb]m nella riga del comando di lancio del nostro file.<br />Di seguito un esempio di esecuzione da riga di comando del file NomeFile.jar, a cui sono stati assegnati 512Mb di memoria heap:<br /><br />java -jar -Xmx512m NomeFile.jarflaviohttp://www.blogger.com/profile/11659260459682203620noreply@blogger.com0tag:blogger.com,1999:blog-5029238993245486217.post-42051998571234567892007-05-15T18:09:00.000+01:002007-05-15T18:15:04.925+01:00ODBC con Microsoft AccessPer creare un database server Access con Windows XP è necessario, una volta creato il database, andare in Pannello di controllo -> Strumenti di amministrazione -> Origine dati (ODBC)<br />Andare nel tab "DSN utente", cliccare su "Aggiungi..." e selezionare "Driver di Microsoft Access (*.mdb)"<br />Cliccare su "Fine", poi assegnare un nome al database e selezionarlo ("Seleziona..."), infine cliccare su "OK".<br />Ora il nostro Data Base Access è visibile dal sistema.flaviohttp://www.blogger.com/profile/11659260459682203620noreply@blogger.com0tag:blogger.com,1999:blog-5029238993245486217.post-74023728768688623732007-05-15T17:59:00.000+01:002007-05-15T18:09:47.496+01:00ODBC Apache TomcatPer poter utilizzare le funzioni di connettività ad un database (Access o MySQL) utlizzando Tomcat, è necessario copiare manualmente il file tools.jar presente nella cartella di Java\jdk1....\lib nella cartella \common\lib di Tomcatflaviohttp://www.blogger.com/profile/11659260459682203620noreply@blogger.com0tag:blogger.com,1999:blog-5029238993245486217.post-75828208245189947032007-05-02T09:53:00.000+01:002007-05-02T09:58:31.675+01:00MySQL dump di una sola tabellaEcco come fare il <span style="font-weight: bold;">dump di una sola tabella</span> con mysqldump; prima di tutto bisogna specificare la tabella di cui vogliamo creare il dump:<br /><blockquote>mysqldump --add-drop-table -u root -p dbName dbTable > table.dump</blockquote>per caricare la tabella di fa:<br /><blockquote>mysql -u root -p dbName < table.dump<br /></blockquote>Per altre informazioni vedere <a href="http://www.eprometeus.com/testi/41363fb81f18d/Database/Database/MySQL:_usare_mysqldump_in_maniera_evoluta.html">qui</a>.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-5029238993245486217.post-9444726620581040262007-03-31T15:30:00.001+01:002007-03-31T15:37:33.405+01:00Bug utilizzo CPU Windows Live Messenger 8.1Ho avuto un problema di utlizzo CPU dopo aver installato l'ultima versione di Windows Live Messenger (ora è la 8.1): dopo pochi secondi di utilizzo infatti la percentuale di utilizzo CPU ha iniziato ad oscillare a valori molto alti toccando molto spesso anche il 100% e rendendo quasi inutilizzabile il sistema. Ho scoperto da <a href="http://www.darcas.net/lab/2007/03/30/windows-live-messenger-senza-banner/#more-34">questo</a> post che il problema è stato riscontrato anche da molti altri utenti e può essere dovuto al fatto che vengono continuamente caricati da Internet dei <span style="font-weight: bold;">banner </span>in Flash. Si può evitare che ciò avvenga andando a modificare il file <span style="font-weight: bold;">hosts</span> contenuto in <em>C:\Windows\System32\Drivers\Etc </em>(presente nei sistemi Windows) andando ad inserire come prima riga la stringa <span style="font-weight: bold;">127.0.0.1 rad.msn.com</span><br />rad.msn.com è l'indirizzo da cui Messenger recupera i banner, ma modificando quella riga di "hosts" si "mente" a Messenger poichè gli si dice di associare a rad.msn.com l'IP 127.0.0.1 che corrisponde a localhost (la macchina stessa su cui si sta lavorando) e su cui ovviamente non sono scaricabili i banner. Windows Live Messenger quindi non è in grado di recuperare quei banner e verrà mostrato semplicemente il logo (fisso) di Windows Live Messenger.flaviohttp://www.blogger.com/profile/11659260459682203620noreply@blogger.com0tag:blogger.com,1999:blog-5029238993245486217.post-5927441468303819932007-03-31T14:56:00.000+01:002007-03-31T15:36:16.861+01:00Problemi di connessione Windows Live Messenger 8.1Sono stati riscontrati problemi di connessione con la versione di Windows Live Messenger 8.1 (l'ultima uscita finora).<br />Consiglio l'installazione di una piccola patch trovata sul blog di Valentino Marangi: <span style="font-weight: bold;">MSN Reapair</span>, consigliata anche da www.downloadblog.it e scaricabile dalla pagina <a href="http://www.valentinomarangi.com/?p=121#">http://www.valentinomarangi.com/?p=121#</a>flaviohttp://www.blogger.com/profile/11659260459682203620noreply@blogger.com0tag:blogger.com,1999:blog-5029238993245486217.post-46787742938861688852007-03-24T12:16:00.000+01:002007-03-24T12:19:22.182+01:00Scrivere su partizioni NTFS da UbuntuPer poter scrivere su un disco Windows da Ubuntu bisogna fare come dice <a href="http://maurolinux.wordpress.com/2007/02/19/lettura-e-scrittura-su-partizioni-ntfs-di-windows/">questo sito</a>. In questo modo Ubuntu vedrà il disco di Windows come delle normali cartelle su cui sarà possibile effettuare tutte le normali operazioni di lettura e <span style="font-weight: bold;">scrittura</span>.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-5029238993245486217.post-63921253995247332922007-03-23T10:49:00.000+01:002007-03-23T12:02:30.170+01:00Creare e eliminare utente MySQLPrima leggere <a href="http://dev.mysql.com/doc/refman/5.0/en/create-user.html">qui</a>, anche per quanto riguarda<span style="font-weight: bold;"> password e privilegi</span>.<br />Per creare un nuovo utente:<br /><blockquote>create user nomeUtente identified by 'stringaPassword';</blockquote>Per eliminare un utente di MySQL si deve fare così:<br /><blockquote>drop user nomeUtente;</blockquote>Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-5029238993245486217.post-74893931160662118232007-03-15T10:38:00.000+01:002007-03-15T10:42:37.069+01:00Connettersi ad un DB MySQL esternoPer connettersi dal proprio pc ad un server MySQL esterno si deve prima di tutto entrare con username e password assegnateci, ad esempio:<br /><blockquote>mysql -u p2p -p</blockquote>Poi fare così:<br /><blockquote>mysql \r nomeDB indirizzoDB</blockquote>Dove indirizzoDB è una cosa del tipo 192.168.1.8. Ora si è connessi e si può iniziare a fare query sul database nomeDB.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-5029238993245486217.post-13904246006609328032007-03-14T21:23:00.000+01:002007-03-23T10:49:21.594+01:00Privilegi a utente MySQLPer creare un nuovo user si usa il seguente comando:<br /><blockquote>GRANT ALL PRIVILEGES ON *.* TO 'p2p'@'%'</blockquote>Così facendo autorizzi p2p a fare quello che vuole da dove vuole su quello che vuole. Se invece vuoi creare un nuovo user che starà solo sul proprio pc allora devi sostituire al % la parola localhost. Per maggiori informazioni vedere <a href="http://dev.mysql.com/doc/refman/4.1/en/adding-users.html">qui</a>.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-5029238993245486217.post-84314787586893833062007-03-14T20:53:00.000+01:002007-03-15T10:37:09.607+01:00Dump di un database MySQLCome recita il sito di MySQL per creare una copia del database si deve scrivere in un terminale questa cosa qui (avendo cura di essere nella cartella bin di MySQL server, oppure di avere settato come variabile di sistema MySQL):<br /><span style="font-weight: bold;">mysqldump --opt --user=username --password=password nomeDB > nomeDB.dump</span><br />Il file .dump verrà creato nella stessa cartella (bin) se non si specifica un percorso diverso. Per caricare il file creato su un altro computer può servire una cosa del genere:<br /><br />mysql -u root -p<br />mysql>CREATE DATABASE nomeDB;<br />mysql> quit<br />mysql -u root -p nomeDB < nomeDB.dump<br /><br />Se non si usano password si omette il <span style="font-weight: bold;">-p</span>. Nel caso si usino più utenti si devono creare, ma questo argomento verrà trattato in un post apposta.Unknownnoreply@blogger.com0