| @ -0,0 +1,10 @@ | |||||
| <?xml version="1.0" encoding="UTF-8"?> | |||||
| <classpath> | |||||
| <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17"> | |||||
| <attributes> | |||||
| <attribute name="module" value="true"/> | |||||
| </attributes> | |||||
| </classpathentry> | |||||
| <classpathentry kind="src" path="src"/> | |||||
| <classpathentry kind="output" path="bin"/> | |||||
| </classpath> | |||||
| @ -0,0 +1,17 @@ | |||||
| <?xml version="1.0" encoding="UTF-8"?> | |||||
| <projectDescription> | |||||
| <name>ConectarObdcToBbdd_BasesDeDatos</name> | |||||
| <comment></comment> | |||||
| <projects> | |||||
| </projects> | |||||
| <buildSpec> | |||||
| <buildCommand> | |||||
| <name>org.eclipse.jdt.core.javabuilder</name> | |||||
| <arguments> | |||||
| </arguments> | |||||
| </buildCommand> | |||||
| </buildSpec> | |||||
| <natures> | |||||
| <nature>org.eclipse.jdt.core.javanature</nature> | |||||
| </natures> | |||||
| </projectDescription> | |||||
| @ -0,0 +1,2 @@ | |||||
| eclipse.preferences.version=1 | |||||
| encoding/<project>=UTF-8 | |||||
| @ -0,0 +1,14 @@ | |||||
| eclipse.preferences.version=1 | |||||
| org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled | |||||
| org.eclipse.jdt.core.compiler.codegen.targetPlatform=17 | |||||
| org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve | |||||
| org.eclipse.jdt.core.compiler.compliance=17 | |||||
| org.eclipse.jdt.core.compiler.debug.lineNumber=generate | |||||
| org.eclipse.jdt.core.compiler.debug.localVariable=generate | |||||
| org.eclipse.jdt.core.compiler.debug.sourceFile=generate | |||||
| org.eclipse.jdt.core.compiler.problem.assertIdentifier=error | |||||
| org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled | |||||
| org.eclipse.jdt.core.compiler.problem.enumIdentifier=error | |||||
| org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning | |||||
| org.eclipse.jdt.core.compiler.release=enabled | |||||
| org.eclipse.jdt.core.compiler.source=17 | |||||
| @ -0,0 +1,18 @@ | |||||
| # README.md | |||||
| ## Titulo | |||||
| Conectar OBDC a Base de Datos | |||||
| ## Autor | |||||
| Alejandro Javier Albus 2CFGS DAM | |||||
| ## Uso | |||||
| Instanciamos el driver de OBDC e intentamos conectarnos a una base de datos. | |||||
| Ya dentro, creamos una nueva tabla y la rellenamos. Confirmamos y acabamos. | |||||
| ## Dependencias | |||||
| Uso de librerias externas: | |||||
| * java.sql.* | |||||
| ## Licencia | |||||
| Uso libre | |||||
| @ -0,0 +1,65 @@ | |||||
| package ConectarObdcToBbdd_BasesDeDatos; | |||||
| import java.sql.*; | |||||
| public class ConectarObdcToBbdd_BasesDeDatos { | |||||
| public static void main( String[] args ) { | |||||
| Connection conexion; | |||||
| Statement sentencia; | |||||
| System.out.println( "> Iniciando el programa .." ); | |||||
| // Cargamos driver ... | |||||
| try { | |||||
| Class.forName( "sun.jdbc.odbc.jdbcOdbcDriver"); | |||||
| } catch( Exception e ) { | |||||
| System.out.println( "- No se ha podido cargar el puente" ); | |||||
| return; | |||||
| } | |||||
| // Establecemos conexion con la base de datos ... | |||||
| try { | |||||
| conexion = DriverManager.getConnection("jdbc:odbc:pruebaodbc", "", ""); | |||||
| sentencia = conexion.createStatement(); | |||||
| /* Borramos tabla si existe ... */ | |||||
| try { | |||||
| sentencia.execute( "DROP TABLE PRUEBA" ); | |||||
| } catch(SQLException sqlerr) { | |||||
| System.out.println("- Ha habido un error ... " + sqlerr.getMessage()); | |||||
| } | |||||
| /* Creamos tabla ... */ | |||||
| sentencia.execute( "CREATE TABLE PRUEBA (" + | |||||
| " ID INTEGER() NOT NULL, " + | |||||
| " NOMBRE VARCHAR(50) NOT NULL, " + | |||||
| " APELLIDOS VARCHAR(50) NOT NULL) " ); | |||||
| sentencia.execute( "INSERT INTO PRUEBA " + "VALUES(1,'JOSE','LOPEZ')" ); | |||||
| sentencia.execute( "INSERT INTO PRUEBA " + "VALUES(2,'PEPE','GARCIA')" ); | |||||
| sentencia.execute( "INSERT INTO PRUEBA " + "VALUES(3,'ROBERTO','JIMENEZ')" ); | |||||
| } catch(Exception e) { | |||||
| System.out.println("- Ha habido un error ... " + e.getMessage()); | |||||
| return; | |||||
| } | |||||
| /* Confirmamos ... */ | |||||
| System.out.println( "+ Se ha creado el objeto correctamente" ); | |||||
| } | |||||
| } | |||||