Created
September 27, 2022 07:38
-
-
Save gcs-abdulwahab/8773c9e79300bb9adc6e8032c8359344 to your computer and use it in GitHub Desktop.
Display Values from Database in JSP Page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%@page import="java.sql.DriverManager"%> | |
<%@page import="java.sql.ResultSet"%> | |
<%@page import="java.sql.Statement"%> | |
<%@page import="java.sql.Connection"%> | |
<% | |
String driver = "com.mysql.jdbc.Driver"; | |
String connectionUrl = "jdbc:mysql://localhost:3306/"; | |
String database = "database"; | |
String userid = "root"; | |
String password = ""; | |
try { | |
Class.forName(driver); | |
} catch (ClassNotFoundException e) { | |
e.printStackTrace(); | |
} | |
Connection connection = null; | |
Statement statement = null; | |
ResultSet resultSet = null; | |
%> | |
<html> | |
<body> | |
<select> | |
<% | |
try{ | |
connection = DriverManager.getConnection(connectionUrl+database, userid, password); | |
statement=connection.createStatement(); | |
String sql ="select id , pname , cnic from patients "; | |
resultSet = statement.executeQuery(sql); | |
while(resultSet.next()){ | |
%> | |
<option><%= resultSet.getString("pname") %> </option> | |
<% | |
} | |
connection.close(); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
%> | |
</select> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment