Bir HTML arama kutusuna bir Dize yazıp bunu ararken bir SQL Sorgusu (Name, Soyad) nasıl oluşturulacağını bulmaya çalışıyorum.HTML arama kutusundan SQL sorgusu oluştur kutusu girdisi
Şimdiye kadar SQL sorgusu içeren bir java sınıfım var. Ayrıca bir jsp dosyası kodladım.
Buna nasıl yaklaşabileceğime dair bir fikrin var mı?
JSP
<%@ page import="java.util.*" %>
<%@ page import="patientensuche.PatientenSuche" %>
<jsp:useBean id="suchen" class="patientensuche.AuslesenBean"
scope="session" />
<jsp:setProperty property="*" name="suchen" />
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset="utf-8">
<title>ErgoTrace-W</title>
<link href="css/mini-reset.css" rel="stylesheet" />
<link href="css/screen.css" rel="stylesheet" media="screen" />
<link rel="icon" href="img/favicon.ico" type="image/vnd.microsoft.icon" />
<link href='https://fonts.googleapis.com/css?family=Oxygen:400,700'
rel='stylesheet' type='text/css'>
<meta name="description" content="ErgoTrace-W Webprojekt" />
<meta name="keywords" content="ZHAW, WEB1, ErgoTrace" />
<meta name="robots" content="index, follow" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<header> <nav>
<ol>
<li class="waehlen"><a href="waehlen.jsp">Patient auswählen</a></li>
<li class="erfassen"><a href="erfassen.jsp">Patient erfassen</a></li>
<li class="suchen"><a href="suchen.jsp">Patient suchen</a></li>
<li class="logout"><a href="index.jsp">Logout</a></li>
<li class="hilfe"><a href="hilfe.jsp">Hilfe</a></li>
</ol>
</nav> </header>
<main> <section> <article>
<h2>Patient suchen</h2>
<form id="searchbox" action="">
<input id="search" type="text" placeholder="Bitte Namen eingeben">
<input id="submit" type="submit" value="Suchen">
</form>
<table border="2">
<thead>
<tr>
<th>Name</th>
<th>Vorname</th>
<th>Strasse</th>
<th>Hausnummer</th>
<th>Ort</th>
<th>Postleitzahl</th>
<th>Krankenkasse</th>
<th>Versicherungsnummer</th>
</tr>
</thead>
</article>
</section>
</main>
<footer>
<%@include file="footer.jsp"%>
</footer>
</body>
</html>
bunu
package patientensuche;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
public class PatientenSuche {
public static void DatenbankAbfrage() {
// Stellt die Verbindung zum Server her
String host = "jdbc:postgresql://localhost:5432/dbergotrace";
String uName = "ergotrace";
String uPass = "ergotrace";
Connection con = DriverManager.getConnection(host, uName, uPass);
try {
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT Name, Vorname FROM Patienten");
while (rs.next()) {
String Anrede = rs.getString("Anrede");
String Vorname = rs.getString("Vorname");
String Nachname = rs.getString("Nachname");
String Strasse = rs.getString("Strasse");
int Hausnummer = rs.getInt("Hausnummer");
int Plz = rs.getInt("Postleitzahl");
String Ort = rs.getString("Ort");
String Krankenkasse = rs.getString("Krankenkasse");
String Versichertennummer = rs.getString("Versichertennummer");
System.out.println(Anrede + " " + Vorname + " " + Nachname + " " + Strasse + " " + Hausnummer + " "
+ Plz + " " + " " + Ort + " " + Krankenkasse + " " + Versichertennummer);
}
}
catch (SQLException err) {
System.out.println(err.getMessage());
}
}
}
Teşekkürler. Başka bir yolu var mı? Çünkü servlet kullanma iznimiz yok. – robhandz