Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Simple example of java connecting to oracle database

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Package cn.com.login.dao;import java.sql.Connection;import java.sql.DriverManager;import java.sql.PreparedStatement;import java.sql.ResultSet;public class LoginDao {public String getUserName (String userCode) {Connection con = null; PreparedStatement pre = null; ResultSet result = null; String userName = ""; try {Class.forName ("oracle.jdbc.driver.OracleDriver") / / load the Oracle driver System.out.println ("start trying to connect to the database!") ; String url = "jdbc:oracle:" + "thin:@10.10.19.19:1521:db123"; String user = "system"; String password = "scc123456"; con = DriverManager.getConnection (url, user, password); System.out.println ("connected successfully") String sql = "select userName from web01_test where userCode =?"; pre = con.prepareStatement (sql); pre.setString (1, userCode); result = pre.executeQuery () While (result.next ()) {userName = result.getString ("userName");} catch (Exception e) {e.printStackTrace () } finally {try {if (result! = null) {result.close ();} if (pre! = null) {pre.close () } if (con! = null) {con.close () } catch (Exception e2) {e2.printStackTrace ();}} return userName;}}

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report