/**
* This interface has all the constants for making JDBC
Connections
*
* @author Darur Venugopal
*
*/
public interface IJDBCConstants {
// In Interface all the variables are public , static
and final
String host = "jdbc:oracle:thin:@localhost:1521:xe";
String username = "HR";
String password = "ORACLE";
String driverName = "oracle.jdbc.driver.OracleDriver";
// Declare methods , In interface just method signature
are defined.
Connection makeConnection();
Statement makeStatement();
// ResultSet getresultSet();
void LoadDriver();
}
How to connect to a database using java: How to select from database using java
private static final String sqlQuery = "select email ,first_name,
last_name from employees";
public static void main(String[] args) {
System.out.println("STEP 1 is LOAD JAVA DRIVER IN THIS RUNNONG
ENVIRONMENT");
IJDBCConstants jdbcImplementor =
new JDBCImplementor();
// valid instantiation
// step 1
jdbcImplementor.LoadDriver();
System.out.println("STEP 2 IS TO MAKE CONNECTION FROM JAVA TO
DATABASE");
Connection connection = jdbcImplementor.makeConnection();
How to insert data into databases like oracle, MySQL, SQLSERVER using java
package jdbc;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class SQLInsertion {
private static final String sqlQuery =
"select email ,first_name, last_name from employees";
private static final String sqlQueryForsql ="select sino, name,place ,email from sqltable";
// insertion statement
private static final String insertQuery ="INSERT INTO SQLTABLE VALUES ( ? , ? , ?,? ) ";
public static void main(String[] args) {
System.out.println("STEP 1 is LOAD JAVA DRIVER IN THIS RUNNONG
ENVIRONMENT");
IJDBCConstants jdbcImplementor =new JDBCImplementor();
while (resultSetForsql.next()) {
System.out.println("11111");
String name =resultSetForsql.getString("name");
String email =resultSetForsql.getString("email");
String place =resultSetForsql.getString("place");
int siNo = resultSetForsql.getInt("sino");
String result = siNo +" " + name + " " + email;
System.out.println(result);
}