初始化

This commit is contained in:
2026-08-25 14:54:16 +08:00
commit 4f2ca4dae3
17 changed files with 779 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
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"));
}
}
}