package org.fhffm.servlet;
...
/**
*
* @author naphaneal
*
*/
public class DBConnMgrServlet extends HttpServlet {
...
final static String host = "localhost";
final static String userid = "root";
final static String passwd = "geheim";
final static String dbname = "myclicker";
final static String port = "3306";
static String connStr = "jdbc:mysql://"+ host + ":" + port + "/" + dbname;
PreparedStatement pstmt = null;
String selectString = "SELECT shortname FROM fragestellung WHERE aktiv=?";
String insertString = "INSERT INTO metadata_http VALUES (?,?,?)";
int id = 1;
String ipaddr = "192.168.10.2";
...
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
Connection conn=null;
PrintWriter out = resp.getWriter();
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection(connStr, userid, passwd);
out.println("Verbindung zu \t" + dbname + "\t hergestellt!");
pstmt = conn.prepareStatement(insertString);
pstmt.setInt(1, id);
pstmt.setString(2, ipaddr);
pstmt.executeUpdate();
out.println("insert erfolgreich");
}...
}