Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package laborator;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import com.mysql.jdbc.Statement;
- class MainApp{
- public static void main(String []args)
- throws SQLException, InstantiationException, IllegalAccessException, ClassNotFoundException{
- String url = "jdbc:mysql://localhost:3306/test";
- Statement sql;
- ResultSet rs;
- Class.forName("com.mysql.jdbc.Driver").newInstance ();
- Connection con = DriverManager.
- getConnection(url, "root", "root");
- sql = (Statement) con.createStatement();
- rs = sql.executeQuery("select * from Persoane");
- while(rs.next())
- System.out.println("id="+rs.getInt("idPersoane")+", nume= "+ rs.getString("nume")+ ", varsta="+rs.getInt(3));
- con.close();
- rs.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement