Connection in form
Hello All!
I want to do an insert into my database using Stored procedures. I already know how to delete and select.. i'm gonna post part of my code in wich i make a select to give u gives an idea of how im doing the statements.. if there's anything wrong please let me know.
privatevoid MostrarActionPerformed(java.awt.event.ActionEvent evt){
Connection conexion;
Statement sentencia;
ResultSet resultado;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch (Exception e){
System.out.println("No se pudo conectar con el JDBC-ODBC");
return;
}
try{
conexion = DriverManager.getConnection("jdbc:odbc:con_sql","","" );
sentencia = conexion.createStatement();
String a = ID_E.getText();
int Empleado_ID = Integer.parseInt(a);
resultado = sentencia.executeQuery("exec x "+a);
while(resultado.next() ){
String Name = resultado.getString("Nombre");
String LastName = resultado.getString("Apellido");
Nom.setText(Name);
Ape.setText(LastName);
}
}
catch( Exception e ){
System.out.println( e );
return;
}
}
# 1
Hi Again!
Well this method is giving me an Sql exception that says:
java.sql.SQLException: [Microsoft][SQL Native Client][SQL Server]Incorrect syntax near 'Empleados'.
My code is trying to insert a new row into a table called Empleados..
Can anyone help me out please?
private void IngresarActionPerformed(java.awt.event.ActionEvent evt) {
Connection conexion;
Statement sentencia;
ResultSet resultado;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch (Exception e){
System.out.println("No se pudo conectar con el JDBC-ODBC");
return;
}
try{
conexion = DriverManager.getConnection("jdbc:odbc:con_sql","","" );
sentencia = conexion.createStatement();
resultado = sentencia.executeQuery("INSERT INTO dbo.Empleados");
while(resultado.next() ){
String i = ID_E.getText();
int id = Integer.parseInt("IDemp");
String Nom = ("Nombre");
String Ape = ("Apellido");
String Ced = ("Cedula");
String FechaN = ("Fecha_Nacimiento");
String Sueldo = ("Sueldo");
String TPrimario = ("Telefono_Primario");
String TSecundario = ("Telefono_Secundario");
String Movil = ("Movil");
String Direccion = ("Direccion");
}
}
catch( Exception e ) {
System.out.println( e );
return;
}
}
# 3
My bad :-/
ok now i'm using the PreparedStatment, wich is for StoredProcedures..
ok so now i dont know exaclty wich statement goes in to the while .next();
here is my code:
private void IngresarActionPerformed(java.awt.event.ActionEvent evt) {
Connection conexion;
Statement sentencia;
resultSet = resultado;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch (Exception e){
System.out.println("No se pudo conectar con el JDBC-ODBC");
return;
}
try{
conexion = DriverManager.getConnection("jdbc:odbc:con_sql","","" );
sentencia = conexion.createStatement();
PreparedStatement insertar = prepareStatement("insertar");
while(.next()){
String i = ID_E.getText();
int id = Integer.parseInt("IDemp");
String Nom = ("Nombre");
String Ape = ("Apellido");
String Ced = ("Cedula");
String FechaN = ("Fecha_Nacimiento");
String Sueldo = ("Sueldo");
String TPrimario = ("Telefono_Primario");
String TSecundario = ("Telefono_Secundario");
String Movil = ("Movil");
String Direccion = ("Direccion");
}
}
catch( Exception e ) {
System.out.println( e );
return;
}
}