import java.sql.*;
public class JdbcGetInt {
public static void main(String args[]) {
Connection con = null;
Statement st = null;
ResultSet rs = null;
String url = "jdbc:mysql://localhost:3306/";
String db = "komal";
String driver = "com.mysql.jdbc.Driver";
String user = "root";
String pass = "root";
try {
Class.forName(driver);
con = DriverManager.getConnection(url + db, user, pass);
st = con.createStatement();
String sql = "select * from person";
rs = st.executeQuery(sql);
System.out.println("Id\tName");
while (rs.next()) {
System.out.print(rs.getInt(1));
System.out.println("\t"+rs.getString(2));
}
rs.close();
st.close();
con.close();
} catch (Exception e) {
System.out.println(e);
}
}
}
|