Rubem_AzenhaPJ 25 de ago. de 2004
voce poderia fazer o metodo retornar o resultset… :lol:
hroberPJ 25 de ago. de 2004
hroberPJ 26 de ago. de 2004
microfilo,
eu andei procurando e como quem procura acha :D resolvi o problema,
vou postar o metodo para se alguem tiver essa duvida possa encontrar assim como eu, obrigado microfilo pela ajuda.
import java.sql.* ;
public class Sql
& # 123 ;
public Statement stmt = null ;
public ResultSet rs = null ;
public Connection conn = null ;
public Sql & # 40 ; & # 41 ;
& # 123 ;
& # 125 ;
public void loadDriver & # 40 ; & # 41 ;
& # 123 ;
try
& # 123 ;
Class . forName & # 40 ; & quot ; com . mysql . jdbc . Driver & quot ; & # 41 ;. newInstance & # 40 ; & # 41 ;;
System . out . println & # 40 ; & quot ; Driver carregado & quot ; & # 41 ;;
& # 125 ;
catch & # 40 ; Exception ex & # 41 ;
& # 123 ;
System . out . println & # 40 ; & quot ; O driver nao pode ser caregado & quot ; & # 41 ;;
& # 125 ;
& # 125 ;
public void authServer & # 40 ; & # 41 ;
& # 123 ;
try
& # 123 ;
conn = DriverManager . getConnection & # 40 ; & quot ; jdbc & # 58 ; mysql & # 58 ; //localhost/java?user=root&password=");
System . out . println & # 40 ; & quot ; usuario logado & quot ; & # 41 ;;
& # 125 ;
catch & # 40 ; SQLException ex & # 41 ;
& # 123 ;
System . out . println & # 40 ; & quot ; SQLException & # 58 ; & quot ; + ex . getMessage & # 40 ; & # 41 ; & # 41 ;;
System . out . println & # 40 ; & quot ; SQLState & # 58 ; & quot ; + ex . getSQLState & # 40 ; & # 41 ; & # 41 ;;
System . out . println & # 40 ; & quot ; VendorError & # 58 ; & quot ; + ex . getErrorCode & # 40 ; & # 41 ; & # 41 ;;
& # 125 ;
& # 125 ;
public ResultSet mysqlQuery & # 40 ; String query & # 41 ;
& # 123 ;
try
& # 123 ;
stmt = conn . createStatement & # 40 ; & # 41 ;;
rs = stmt . executeQuery & # 40 ; query & # 41 ;;
& # 125 ;
catch & # 40 ; SQLException e & # 41 ;
& # 123 ;
System . out . println & # 40 ; & quot ; Nao foi possivel efetuar query & quot ; & # 41 ;;
& # 125 ;
return rs ;
& # 125 ;
public static void main & # 40 ; String args & # 91 ; & # 93 ; & # 41 ;
& # 123 ;
Sql a = new Sql & # 40 ; & # 41 ;;
a . loadDriver & # 40 ; & # 41 ;;
a . authServer & # 40 ; & # 41 ;;
ResultSet query = a . mysqlQuery & # 40 ; & quot ; select * from users & quot ; & # 41 ;;
try
& # 123 ;
while & # 40 ; query . next & # 40 ; & # 41 ; & # 41 ;
& # 123 ;
String id = query . getString & # 40 ; & quot ; uid & quot ; & # 41 ;;
String login = query . getString & # 40 ; & quot ; login & quot ; & # 41 ;;
String pass = query . getString & # 40 ; & quot ; password & quot ; & # 41 ;;
System . out . println & # 40 ; & quot ; Id -& gt ; & quot ; + id + & quot ; login -& gt ; & quot ; + login +& quot ; password -& gt ; & quot ; + pass & # 41 ;;
& # 125 ;
& # 125 ;
catch & # 40 ; SQLException e & # 41 ;
& # 123 ;
System . out . println & # 40 ; & quot ; Nao foi possivel mostrar os dados & quot ; & # 41 ;;
& # 125 ;
& # 125 ;
& # 125 ;
- Tá ai, bem simples :)