Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- public class DAO {
- /**
- * @param args
- */
- /**
- * @param args
- */
- public boolean AbreBanco(){ //pode ser void também, mas eu prefiro boolean, assim podemos controlar melhor o resultado
- // TODO Auto-generated method stub
- Connection conexao = null;
- Statement stmt = null;
- ResultSet rs = null;
- try{
- Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
- String driver = "jdbc:sqlserver://P10-LAB01-PC05:1433;databaseName=lp2;user=sa;password=fmu;";
- conexao = DriverManager.getConnection(driver);
- stmt = conexao.createStatement();
- rs=stmt.executeQuery("SELECT * FROM dbo.taluno");
- while(rs.next()){
- System.out.print(rs.getInt("Id")+"\t");
- System.out.print(rs.getString("Nome")+"\t");
- System.out.println(rs.getString("email"));
- }
- rs.close();
- stmt.close();
- conexao.close();
- }
- catch(Exception ex){
- ex.printStackTrace();
- }
- return AbreBanco;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement