Saltar al contenido

creando un objeto de conexión en el ejemplo de código java

Ejemplo 1: crear una conexión jdbc en java

packagecom.java2novice.jdbc;importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.SQLException;importjava.sql.Statement;publicclassJdbcConnectionpublicstaticvoidmain(String a[])tryClass.forName("oracle.jdbc.driver.OracleDriver");Connection con =DriverManager.getConnection("jdbc:oracle:thin:@::","user","password");Statement stmt = con.createStatement();System.out.println("Created DB Connection....");catch(ClassNotFoundException e)// TODO Auto-generated catch block
            e.printStackTrace();catch(SQLException e)// TODO Auto-generated catch block
            e.printStackTrace();

Ejemplo 2: crear conexión en jdbc

Connection=Helps our java project connect todatabaseStatement=Helpstowrite and execute SQL query
ResultSet=ADataStructure where the data from query result stored
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++After succesfully created the connect
next step is STATEMENT

Statement statement = connection.createStatement();We use createStatement() method tocreate
the statement from our connection.-The result we get from this type of statement
can only move from top tobottom,
not other way around

Statement statement = connection.createStatement(ResultSet TYPE_SCROLL_INSENSITIVE
,ResultSet CONCUR_READ_ONLY);-The result we get from this type of
statement can freely move between rows

Once we have statement we can run
the query and get the result toResultSet format 
		importjava.sql.ResultSet;We use the method executeQuery()toexecute our queries

ResultSet result = statement.executeQuery("Select * from employees");

Tienes la opción de añadir valor a nuestra información dando tu veteranía en los informes.

¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)



Utiliza Nuestro Buscador

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *