Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- import com.mysql.jdbc.Statement;
- public class testJDBC2 {
- 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("Id")+", nume= " + rs.getString("nume")+ ",
- varsta="+rs.getInt(3));
- con.close();
- sql.close();
- rs.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement