Código java:
Ver original/**
*
* @author Soma
*
*
*/
package BD;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class BD {
private String driverClassName
;
this.user = user;
this.password = password;
this.url = url;
this.driverClassName = driverClassName;
}
public BD()
{
this.user = "root";
this.password="tupass";
this.url = "jdbc:mysql://localhost/tu_basedatos";
this.driverClassName = "com.mysql.jdbc.Driver"; // driver
}
return password;
}
return url;
}
return user;
}
public void setPassword
(String password
) { this.password = password;
}
public void setUrl
(String url
) { this.url = url;
}
return conn;
}
this.conn = conn;
}
public void setDriverClassName
(String driverClassName
) { this.driverClassName = driverClassName;
}
public String getDriverClassName
() { return driverClassName;
}
this.user = user;
}
try {
Class.forName(this.driverClassName).newInstance();
this.
conn = DriverManager.
getConnection(this.
url,
this.
user,
this.
password);
System.
out.
println("Error " + err.
getMessage()); }
}
this.stmt = conn.createStatement();
return this.stmt.executeQuery(sql);
}
this.stmt = conn.createStatement();
stmt.executeUpdate(sql);
}
}
return st.executeUpdate(Q);
}
this.conn.close();
}
}
Te recomiendo usar esa clase para llamar a conexion de base de datos aqui un ejemplo de como usarlo
Código java:
Ver originaltry{
con.conectar();
//haciendo pruebas
ResultSet datos
= con.
ExeGet("select * from persona where rut='"+form.
getRut()+"';"); //sacamos todo del resulset
while(datos.next()){
//lo enviamos a un page input y lo imprimimos para verlo en la consola tambien
System.
out.
println("rut :"+ datos.
getObject("rut")); System.
out.
println("nombre :"+ datos.
getObject("nombre")); System.
out.
println("edad :"+ datos.
getObject("edad")); System.
out.
println("direccion : "+ datos.
getObject("direccion")); //////////////////outposts
f.addActionOutput("rut", datos.getObject("rut"));
f.addActionOutput("nombre", datos.getObject("nombre"));
f.addActionOutput("edad", datos.getObject("edad"));
f.addActionOutput("direccion", datos.getObject("direccion"));
}
con.Off();
System.out.println("rut :"+ datos.getObject("rut")); // aqui sacas el rut del campo llamado rut... si tienes dudas pregunta