Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.Statement;
- import java.sql.SQLException;
- class JDBCTest {
- private static String user =”root”;
- private static String password = “123456”;
- private static Connection con=null;
- private static Statement st=null;
- private static ResultSet rs=null;
- public static void main(String args[])throws Exception {
- try {
- Class.forName(“com.mysql.jdbc.Driver”);
- con = DriverManager.getConnection(“jdbc:mysql://localhost:3306/dbdbdbd”, user, password);
- }
- catch (Exception e) {
- System.out.println(“e”);
- }
- try{
- st=con.createStatement();
- rs=st.executeQuery(“select * from student”);
- while(rs.next()) {
- System.out.println(rs.getString(“Last_Name”));
- }
- }
- finally {
- try {
- if (rs != null) {
- rs.close();
- }
- if (st != null) {
- st.close();
- }
- if (con != null) {
- con.close();
- }
- }
- catch (SQLException e) {
- System.out.println(e);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment