package jdbctest;
import java.sql.*;
public class JDBCTEST {
public static void main(String[] args)throws SQLException {
Connection myConn = null;
Statement myStmt = null;
ResultSet myRs = null;
try {
// 1. Get a connection to database
myConn = DriverManager.getConnection("jdbc:mysql://localhost:3306/College", "root" , "niit");
System.out.println("Database connection successful!\n");
// 2. Create a statement
myStmt = myConn.createStatement();
// 3. Execute SQL query
myRs = myStmt.executeQuery("select * from student");
// 4. Process the result set
while (myRs.next()) {
System.out.println(myRs.getString("id") + ", " + myRs.getString("name"));
}
}
catch(Exception e)
{}
}
}
|
No comments:
Post a Comment