Como hago una conexion Java Eclipse para insertar datos en una BD Postgress
Publicado por Edita (1 intervención) el 03/02/2016 02:01:26
Hola amigos ... porfavor pueden ayudarme a hacer una conexion desde Eclipse a Postgress para insertar datos ... hasta ahora esto es lo que tengo ... y es asi como debos hacerlo solo que no se coom hacer la conexion
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"
import = "java.sql.*"
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="Index.jsp" method = "post">
<table width="545" height="270" border="2">
<tr>
<td height="42" colspan="2"><div align="center"><em><strong>INGRESO DE DATOS ESTUDIANTILES </strong></em></div></td>
</tr>
<tr>
<td><em><strong>Id_Estudiante:</strong></em></td>
<td><em><strong><input type="text" name="txtid"/></strong></em></td>
</tr>
<tr>
<td><em><strong>Cedula:</strong></em></td>
<td><em><strong><input type="text" name="txtced" /></strong></em></td>
</tr>
<tr>
<td><em><strong>Nombres:</strong></em></td>
<td><em><strong><input type="text" name="txtnom"/></strong></em></td>
</tr>
<tr align="center">
<td colspan="2"><em>
<strong>
<input type="submit" name="btn1" value="GUARDAR DATOS"/></strong></em></td>
</tr>
</table>
</form>
<%
String ConString = "jdbc:postgresql://localhost:5432/ESTUDIANTES";
String user = "postgres";
String pass = "johana";
try
{
Class.forName("org.postgresql.Driver");
Connection con = (Connection) DriverManager.getConnection(ConString,user,pass);
Statement st = con.createStatement();
ResultSet rs = st.executeUpdate("INSERT INTO public.\"Tb_Persona\"(`Id_Persona`,`Cedula`,`Nombres`) VALUES ('txtid','txtced','txtnom')");
out.println("<br> SE A EJECUTADO CORRECTAMENTE");
st.close();
con.close();
}
catch(Exception e)
{
out.println("ERROR EN EL SISTEMA, VUELVA A INTENTARLO");
}
%>
</body>
</html>
Valora esta pregunta


0