Pure java driver Oracle instance about local protocol
package util;
import java.sql.*;
public class JdbcUtil {
static {
String driver = "oracle.jdbc.driver.OracleDriver"; //Load the driver, only need to load it once
try {
Class.forName(driver);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//Static method to obtain connection
public static Connection getConnection() { In programming, we often need to interact with databases. In this process, obtaining a database connection is a very critical step. In Java, we can use JDBC to implement database connections. The getConnection() method is a static method in JDBC, used to obtain the database connection object. This method usually requires passing in some parameters, such as the URL of the database, user name and password, etc. The specific parameters will vary depending on the database you are using. When writing code, you can follow the steps below to use the getConnection() method to get
String url = "jdbc:oracle:thin:@127.0.0.1:1521:database";
String user = "username";
String pwd = "password";
Connection con = null;
try {
con = DriverManager.getConnection(url, user, password);
} catch (SQLException e) {
e.printStackTrace();
}
return con;
}
}
The source code of the urgent java graduation project topic selection system with the database connection is
Core code:
public void actionPerformed(ActionEvent e) { This method is used to handle triggered events. In this method, you can write appropriate code to respond to the event. Different actions can be performed based on the type of event, such as performing certain actions when a button is clicked, or performing other actions when a menu item is selected. In this method, you can use the event object e to obtain relevant information, such as obtaining the component that triggered the event, obtaining the event type, etc. According to specific needs, we can write corresponding logic code in this method to achieve what we want
if(e.getSource() == add){
this.setVisible(false);
new AddPanel();
}
if(e.getSource() == modify){
this.setVisible(false);
new ModifyPanel();
}
if(e.getSource() == search){
this.setVisible(false);
new SearchPanel();
}
if(e.getSource() == exit){
System.exit(0);
}
}
..........
With complete source code
Use java to get data from Oracle database
8.Oracle8/8i/9i database (thin mode)
//import java.sql.*;
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance(); In this line of code, we use Java's reflection mechanism to dynamically load and instantiate the Oracle database driver. By calling the forName method of the Class class and passing in the driver's fully qualified name "oracle.jdbc.driver.OracleDriver" as a parameter, we can load the driver into memory. Next, use the newInstance method to create an instance object of the driver. In this way, we can use the driver to connect and operate the Oracle database in subsequent code.
String url="jdbc:oracle:thin:@localhost:1521:orcl"; //orcl is the SID of the database, indicating that the Oracle database instance name connected to the local host is orcl
Connection conn = DriverManager.getConnection(url, "username", "password");
Statement stmtNew = conn.createStatement(); creates a Statement object associated with the database connection. This Statement object can be used to execute SQL statements and return results.
20. Store binary field data in the database
InputStream pic = new FileInputStream(dto.get(i).getLibPic()); is a line of code about the input stream. Its function is to create an input stream pic based on the libPic path specified by the i-th element of dto. libPic is a file path. This file is converted into an input stream through FileInputStream for subsequent operations.
sql = "INSERT INTO piclib (name,pic,sign,remark) VALUES (?,?,?,?)";
pstmt = con.prepareStatement(sql);
pstmt.setString(1, dto.get(i).getName()); This line of code sets the name of the i-th object in the list as the first parameter of PreparedStatement.
pstmt.setBinaryStream(2, pic, (int)dto.get(i).getLibPic().length()); The pic in the statement is a binary stream used to store picture data. Here, we pass pic as the second parameter to the setBinaryStream method of the pstmt object. And dto.get(i).getLibPic().length() is the length of the obtained image data, which is converted to int type and passed to the setBinaryStream method as the third parameter. In this way, the image data can be stored in the database.
21. Retrieve binary field data from the database
//import java.sql.*;
public class DemoDisplayBinaryDataFromDatabase {
public static Connection getConnection() throws Exception {
String driver = "oracle.jdbc.driver.OracleDriver";
String url = "jdbc:oracle:thin:@localhost:1521:databaseName";###
String username = "name";
String password = "password";
Class.forName(driver);
Connection conn = DriverManager.getConnection(url, username, password); is the code used to establish a database connection in Java. It uses the JDBC (Java Database Connectivity) API to obtain a connection to the database by specifying the URL, username and password of the database. This line of code is a key step in connecting to the database. It will return a Connection object. We can use this object to perform subsequent database operations, such as executing SQL statements, querying the database, etc.
return conn;
}
public static void main(String args[]) throws Exception { //Write your code logic here }
Connection conn = null;
ResultSet rs = null;
PreparedStatement pstmt = null;
String query = "SELECT raw_column, long_raw_column FROM binary_table WHERE id = ?";
try {
conn = getConnection();
Object[] results = new Object[2];
pstmt = conn.prepareStatement(query); is a common line of Java code used to create a precompiled SQL statement object. This object can be used to perform database queries or update operations. By passing a specific SQL query or update statement to this method, we can prepare a query or update operation that can be used repeatedly. This can improve the efficiency of database operations and prevent SQL injection attacks. This method requires a valid database connection object conn and a SQL statement query as parameters. By calling this method, we can get
pstmt.setString(1, "0001");
rs = pstmt.executeQuery();
rs.next();
Implement binary data on the client
results[0] = rs.getBytes("RAW_COLUMN");
results[1] = rs.getBytes("LONG_RAW_COLUMN");
} finally {
rs.close();
pstmt.close();
conn.close();
}
}
}
The above is the detailed content of Oracle Example of Java Driver Implementing Native Protocol. For more information, please follow other related articles on the PHP Chinese website!

Some Windows 11/10 users report that they see a cmd window open up right after a Bitdefender update and it is running SecureBootEncodeUEFI.exe. This post from php.cn introduces how to remove the SecureBootEncodeUEFI.exe Trojan.

Sysdll_win64_retail.dll is a dynamic link library (DLL) file related to the FIFA 17 application. When that file gets missed or corrupted, a series of issues and errors will happen about that application. To resolve this issue, you can read this artic

Many SurfaceBook users report that they meet the “core isolation blocked by ew_usbccgpfilter.sys” issue on Windows 11/10. This post from php.cn helps to fix the annoying issue. Keep on your reading.

When you press Ctrl Alt Del on your computer, you will enter the Security Options window, where you might see Lock, Switch user, and Sign out options. Do you know that these options can be changed? This php.cn post will show you how to remove opt

Some Windows 11/10 users report that their Windows Defender has spotted a virus named Virus:Win32/Grenam.VA!MSR. But they don’t know how to remove it. This post from php.cn teaches you how to remove Virus:Win32/Grenam.VA!MSR.

When you need to visit a website frequently, it is quite troublesome to open a browser and search for it every time. Why don’t you try to save a website as an app? If you do this, you can open it as normal software. Here, php.cn offers you some usefu

Some people encountered the error code 0x00000000 on Windows 11 when they installed the latest Windows update. What should you do to cope with this unexpected error? This article on the php.cn Website will give you some clues for troubleshooting.

Are you suffering from the error message "FileType selected not supported by this app" when opening files in Teams or Excel? Now read this post from php.cn to get several useful solutions to this issue.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

WebStorm Mac version
Useful JavaScript development tools