j2ee|oracle| Data | Database in the Java EE application development, the application and the database connection establishment is one of the problems that we often encounter. Here I talk about connecting Oracle databases through O
The connection with Oracle database in Java application
Author: 洪建
In the Java EE application development, the application and the database connection establishment is one of the proble
The operation of the database is one of the necessary development parts of the current system development, especially in the large data age, the database is especially important. But you really know how Java and the database are connected.
Let's give you a simple example of a data
The operation of the database is one of the necessary development parts of the current system development, especially in the large data age, the database is especially important. But do you really understand how Java and the database are connected?
Let's give you a simple example of a
Java query the Oracle Database Cluster connection string and JDBC jar package selection. event: The report interface database suddenly fails to be connected, resulting in a failure to retrieve data normally. exception information: Io exception: got minus one from a read call
password you chose to set when installingcon = drivermanager.getconnection (url, user, password);//Get connectionSYSTEM.OUT.PRINTLN ("Connection Successful! ");String sql = "SELECT * from student where name=?"; /precompiled statement, "? The delegate parameterPre = con.preparestatement (SQL);//instantiation of precompiled statementsPre.setstring (1, "Liu Xianhan");//Set the parameter, the preceding 1 indicates the index of the parameter, not the inde
Label:Just to implement a function, so write only one method, for easy invocation, set as static method 1 Packagecom.jv;2
3 Importjava.sql.Connection;4 ImportJava.sql.DriverManager;5
6 Public classLianjie {7
8 //static method Gets the Connection object
9 Public StaticConnection Getlianj ()throwsExceptionTen {
One
AClass.forName ("Oracle.jdbc.driver.OracleDriver"); -
-String url = "Jdbc:oracle:thin: @localhost: 1521:orcl
In the Java EE application development, the application and the database connection establishment is one of the problems that we often encounter. Here I talk about connecting Oracle databases through OCI, thin, and jdbcodbc bridges in local applications, iplanet Application Server 6.5 and Sun one application server 7 T
dburl= "Jdbc:oracle:thin: @localhost: 1521:ORCL";//connecting to an Oracle databaseString username= "admin";//login account and password for the databaseString password= "Admin"; Connection=drivermanager.getconnection (Dburl,username,password); String SQL= "SELECT * FROM Student"; //Create a PreparedStatement object to send the parameterized SQL statement to the databa
Customerdao interface, and use JDBC to complete the corresponding database operation.Summarize:1. use config to load the database configuration file so that if you change the configuration of the database, you only need to change the configuration information in the file, you do not have to modify the code. 2.thefunction operation in the Bank class, the operati
Catch block
$ e.printstacktrace ();Panax Notoginseng }
- returncn; the }
+
A /*
the * Close result set, operation, connection + */
-
$ Public voidClose (ResultSet rs,preparedstatement ps,connection cn) { $ Try{
- //determine if the value is null
- if(rs!=NULL){
the rs.close (); - }
Wuyi if(ps!=NULL
Java wants to connect to a database first to introduce a database driver package1 Final StaticString drive = "Oracle.jdbc.driver.OracleDriver";2 Final StaticString Oracleurl = "Jdbc:oracle:thin: @xx. Xxx.xx.xx:1521:orcl";3 Final StaticString dbuser= "Studio";4 Final StaticString password= "Studio";5 6 Public voidExcutesearch (String str)7 {8Connection conn =NULL
To import a package:Import java.sql.Connection;Import Java.sql.DriverManager;Import java.sql.PreparedStatement;Import Java.sql.ResultSet;Import java.sql.SQLException;Declaring variables:private static String Usernamr = "LSDB"; Database user name, in MySQL all database user name password is the same, Oracle database use
post-precompile. PreparedStatement ps=conn.preparestatement (SQL); //Input ParametersPs.setint (1, 6);//The first one is the parameter index, and the second is the value. Ps.setstring (2, "SSS"); Ps.setstring (3, "18"); if(Ps.execute ()) {System.out.println ("Record added successfully"); }
//precompilation: Modifying Records//String sql= "update student set pass=? where Name=?";//preparedstatement ps=conn.preparestatement (SQL);//ps.setstring (1, "666");//ps.setstring (
Ways to connect to an Oracle databaseFormat one: Oracle JDBC Thin using a servicename:jdbc:oracle:thin:@//:/EXAMPLE:JDBC:ORACLE:THIN:@//192.168.2.1:1521/XE Note the format here, which is followed by//, which is the main difference from using SIDS.This format is recommended by Oracle because the SID for each node is different for the cluster, but the service_name
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.