Code:
import java.sql.*;
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
//import com.oreilly.servlet.multipart.*;
public class NewsSystemLogin2 extends HttpServlet {
final String host = "81.209.184.77";
final String database = "datenbankname";
final String user = "benutzername";
final String password = "passwort";
PrintWriter out ;
public void doGet(HttpServletRequest request,
HttpServletResponse response) throws IOException {
out = response.getWriter();
response.setContentType("text/html");
out.println("<html><head><title>News-System Login-Bereich</title></head>");
out.println("<body>");
out.print("<center><h1><u>Login-Bereich:</u></h1></center>
");
out.print("<center><table width=\"270\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
out.print("<tr><td><form name=\"adminlogin\" method=\"post\" action=\"NewsSystemLogin\">");
out.print("Login:</td><td><input type=\"text\" name=\"login\" value=\"login\" size=\"10\"></td></tr>");
out.print("<tr><td>Passwort:</td><td><input type=\"password\" name=\"pass\" value=\"pass\"></td></tr>");
out.print("<tr><td><input type=\"submit\" name=\"submit\" value=\"ok\"></td>");
out.print("<td><input type=\"reset\" name=\"reset\" value=\"cancel\"></td></tr>");
out.println("</form>");
out.println("</body>");
out.println("</html>");
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String login=request.getParameter("login");
String pass=request.getParameter("pass");
out = response.getWriter();
response.setContentType("text/html");
out.write("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Strict//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">");
out.write("<html>");
out.write("<head>");
out.write("<title>Admin-Bereich</title>");
out.write("</head>");
out.write("<body>");
try {
Class.forName ("com.mysql.jdbc.Driver");
//Class.forName ("org.gjt.mm.mysql.Driver");
Connection conn = DriverManager.getConnection ( "jdbc:mysql://"+host+"/"+database, user, password); // user, passwd
//out.println("
login attempt was successful </p>");
// Any warnings generated by the connect?
//checkForWarning(conn.getWarnings());
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT news_config.adminname, news_config.adminpass FROM news_config");
out.println(rs);
stmt.close();
conn.close();
}
catch (ClassNotFoundException e) { out.println("Can't load driver " + e);}
catch (SQLException e) { out.println("Database access failed " + e);}
out.println("</body>");
out.println("</html>");
}
}
Database access failed: java.sql.SQLException: No suitable driver
Was mach ich falsch? Falsches URL Format? Falscher MySQL Driver? (<= falsch installiert?)
Ich fummel jetzt schon 3 Tage an meinem Server rum, aber es will einfach nicht :roll: