23 lines
867 B
Java
23 lines
867 B
Java
package com.example.demo2;
|
|
|
|
import javax.servlet.http.HttpServlet;
|
|
import java.sql.*;
|
|
|
|
public class MyselectServlet extends HttpServlet {
|
|
public static void main(String[] args) throws ClassNotFoundException, SQLException {
|
|
Class.forName("com.mysql.jdbc.Driver");
|
|
String url = "jdbc:mysql://localhost:3306/demo1";
|
|
Connection connection = DriverManager.getConnection(url,"root","root");
|
|
//System.out.println(connection);
|
|
String sql = "select * from admin where id=1";
|
|
Statement statement = connection.createStatement();
|
|
ResultSet rs = statement.executeQuery(sql);
|
|
System.out.println(rs);
|
|
while (rs.next()) {
|
|
//System.out.println(rs.getInt("id"));
|
|
System.out.println(rs.getString("username"));
|
|
System.out.println(rs.getString("password"));
|
|
}
|
|
}
|
|
}
|