tenho uma classe coneção
import java.sql.Connection;
import java.sql.DriverManager;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class Database {
private static Connection connection;
private static String databaseName = "teste";
private static String databaseUsername = "root";
private static String databasePassword = "ryouta";
private static String driver = "com.mysql.jdbc.Driver";
public Connection getConnection() {
createConnection();
return connection;
}
public static void createConnection() {
if (connection == null) {
try {
Class.forName(driver);
String url = "jdbc:mysql://localhost/" + databaseName;
connection = DriverManager.getConnection(
url, databaseUsername, databasePassword);
System.out.print("Conexão estabelecida");
} catch (Exception e) {
JOptionPane.showMessageDialog(new JFrame(),
"Database connection could not be established." +
"Please check your network connection and restart.",
"Error Message", JOptionPane.ERROR_MESSAGE);
e.printStackTrace();
connection = null;
}
}
}
public static void main(String[] args) {
createConnection();
}
}
tenho um jsp
<html>
<head>
<title>Pizzaria Ryouta</title>
<script type="text/javascript">
function alerta(){
formulario = document.nomedoform;
login = formulario.loginsistema.value;
senha = formulario.senhasistema.value;
if(login.length < 3 || senha.length == 0 ){
alert("Não pode haver nome com menos de 3 caracter");
}
}
</script>
</head>
<body>
<center>
<h1>Pizzaria Ryouta</h1>
<form action="cadastro" name="nomedoform">
<table border="1">
<tr>
<td>Login:</td>
<td>
<input type="text" name="loginsistema">
</td>
</tr>
<tr>
<td>Senha:</td>
<td>
<input type="password" name="senhasistema">
</td>
</tr>
<tr>
<td>
<a >Cadastrar</a>
</td>
<td>
<input type="submit" value="Entrar no sistema" onclick="alerta()">
</td>
</tr>
</table>
</form>
</center>
</body>
</html>
tenho uma servelet
import java.io.IOException;
import java.sql.SQLException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class cadastro
*/
public class cadastro extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public cadastro() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String login= request.getParameter("loginsistema");
String senha=request.getParameter("senhasistema");
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
}
como faço para insserir os dados passados pelo jsp !!! no mysql a tabela jah tah criada com os campos correto! e o drive de coneção jah tah adicionado ! Ajuda porfavor