8th
Sat Nov 02 2024 01:41:25 GMT+0000 (Coordinated Universal Time)
Saved by
@sem
use itb;
create table students(name varchar(50),rollno int,branch varchar(20));
insert into students (name,rollno,branch) values
('niha',90,'it'),
('nishka',95,'it'),
('nishu',96,'it');
JAVA
package jdbc;
import java.sql.*;
public class Simple_Connection {
Connection conn = null;
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
Class.forName("com.mysql.cj.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/itb","root","root");
Statement stmt = conn.createStatement();
ResultSet rs=stmt.executeQuery("Select * from students");
while(rs.next()){
System.out.println(rs.getString(1)+" "+rs.getInt(2)+" "+rs.getString(3));
}
conn.close();
}catch(Exception e) {
e.printStackTrace();
}
}
}
content_copyCOPY
Comments