Este dilema se puede abordar de diferentes formas, pero nosotros te damos la respuesta más completa en nuestra opinión.
Ejemplo 1: crear una conexión jdbc en java
package com.java2novice.jdbc;import java.sql.Connection;import java.sql.DriverManager;import java.sql.SQLException;import java.sql.Statement;public class JdbcConnection
public static void main(String a[])
try
Class.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 connecttodatabase
Statement =
Helps towriteandexecuteSQL query
ResultSet =
A DataStructure where the datafrom query result stored
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++After succesfully created the connectnext step is STATEMENT
Statement statement = connection.createStatement();
We use createStatement() method tocreate
the statement from our connection.-The result we get from this typeof statement
can only move fromtopto bottom,not other way around
Statement statement = connection.
createStatement(ResultSet TYPE_SCROLL_INSENSITIVE
,ResultSet CONCUR_READ_ONLY);-The result we get from this typeof
statement can freely move betweenrows
Once we have statement we can run
the query and get the result to
ResultSet format
import java.sql.ResultSet;
We use the method executeQuery()toexecute our queries
ResultSet result = statement.
executeQuery("Select * from employees");
Reseñas y puntuaciones del tutorial
Tienes la posibilidad dar visibilidad a esta división si lograste el éxito.
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)