Oracle transaction processing and instance demonstration jdbc operation batch DeletionTransactions
As the basic unit of logical processing, database operations are composed of one or more SQL statements. Of course, there are also non-database operations, such as the Restore Point Set in the computer is a good application.
The basic nature of transactions is described in another article: SQL transactions and
name private static String classname= " Oracle.jdbc.driver.OracleDriver " ; Url private static String url="Jdbc:oracle:thin : @192.168.2.2:1521:java46 " ; Connect to database user name private static String username= "Scott" ;Password to connect to the database private static String password= "NIIT" ;Declares aConnection private static Connection Connection = Null; The method is statically decorated to form a static code block, and the value is loaded oncePubl
There are usually four connection methods to choose from. Here I only use two of themI use tomcat under win98The server is winnt and Oracle is installedMy class path is: D: omcatwebappsROOTWEB-INFclassesyourpackageJsp path: D: omcatweb‑rootCall path: http: // 127.0.0.1: 8080/connOracle. jsp(You can't do it. You can try my path ^_^)1. Use the JDBC_ODBC bridge to connectFirst, remember to create an ODBC connection in the system data source. ^ _ ^ (you c
There are usually four connection methods to choose from. Here I only use two of themI use tomcat under win98The server is winnt and Oracle is installedMy class path is: D: omcatwebappsROOTWEB-INFclassesyourpackageJsp path: D: omcatweb‑rootCall path: http: // 127.0.0.1: 8080/connOracle. jsp(You can't do it. You can try my path ^_^)1. Use the JDBC_ODBC bridge to connectFirst, remember to create an ODBC Connection in the system data source. ^ _ ^ (y
Use JDBC to modify the Oracle sequence step in batches
Scenario
After the data migration is complete, you need to reset the sequence in the database ,.
Method
Three Common Methods
Delete-recreate
In this way, Simple Sequence reconstruction will affect the business logic processing and cannot adapt to the inconsistency of original sequence Parameter rules. However, if the sequence parameters are consistent,
data rollback failed!") ");}}Log.error ("Cleanup data failed with error message:" +ex.getmessage ());} finally {if (null! = conn) {try {Conn.close ();} catch (SQLException se) {Log.error ("Clean data, shut down database failed!");}}} The second type: in a separate query The amount of data in the SQL must not exceed 1000Workaround:For exampleSelect * FROM table_name where col in (' col1 ', ' col2 ' ...)If the item in the back is too large, this error will occur over 1000.The workaround is to:Sel
The 1.Spring built-in NativeJdbcExtractor converters include:C3p0nativejdbcextractorCommonsdbcpnativejdbcextractorJbossnativejdbcextractorNativeJdbcExtractorNativejdbcextractoradapterSimplenativejdbcextractorWeblogicnativejdbcextractorWebspherenativejdbcextractorXapoolnativejdbcextractorchange the server in a timely manner to avoid wasting a lot of time.located under Org\springframework\jdbc\support\nativejdbc Converting a connection from a database
How to connect MySQL, Oracle, SQL Server database JDBC mysql: add a MySQL jar package first String url= "jdbc:mysql://localhost:3306/database name"; //Database address String name= "root";//database user name String password= "123456";// Database user Password Class.forName ("Com.mysql.jdbc.Driver");//load MySQL driver Connection conn = Drivermanager.getconnection ( Url,name,passWOrd);//Connection
user, String password );
Note: Obtain the database connection according to the url. the user is the username used to log on to the database, and the password is the login password.
Database url Description: The url is written as: localhost can be replaced by the return address 127.0.0.1 pointing to the Local Machine
Common Database url:
Oracle -- jdbc: oracle: t
1. Create a table
Create Table stud (Sid int,Sname varchar2 (50 ),Age number,Score number (4, 2 ))And insert some data (manually insert some data)2. Create a function
Create or replace function fun_getscores (V_age in stud. Age % Type)Return numberIsV_score number;BeginSelect sum (score) into v_score from stud where age> v_age;Return v_score;-- Exception HandlingExceptionWhen others thenDbms_output.put_line (sqlcode | sqlerrm );Return-1;End;3. Call in JDBC
Label:Article turned from: http://blog.itpub.net/22664653/viewspace-1383092/ObjectiveThis article is a learning note to learn how to connect to Oracle through Java JDBC/OJDBC in several ways.One use methodMethod One: Connect to Oracle using SERVICE_NAMEJdbc:oracle:thin:@//Example: Jdbc:oracle:thin:@//10.10.10.1:1521/tdbNote The format here, which is followed by//
Import java. SQL .*;
Public class ora8iconnect{Public ora8iconnect (string dB, string ID, string PWD){Dbname = dB;Userid = ID;Userpwd = PWD;Beginconnect (); // connect to the database}/*-* Returns a connection object.*/Public connection getconnection () {return conn ;}
/*-* Connect to the database. If the connection succeeds, 1 is returned. Otherwise, 0 is returned.*/Public int beginconnect (){Try{// Load an oracle driverDrivermanager. register
Jdbc oracle Database isolation levelDatabase isolation level:When these transactions access the same data in the database, if the necessary isolation mechanism is not adopted, various concurrency problems will occur:Dirty read: For two objects T1, T2, T1, after reading fields that have been updated by T2 but have not been submitted, if T2 rolls back,The content read by T1 is temporary and invalid.Repeatable
Some of the most common errors in JDBC access to Oracle databases. The example in the sample code and/or comment column shows the type of SQL statement that caused the error or additional comments about the specific error that is displayed on the row in the table.
Table 1
Error Mark
Oracle Error
SQLState
Sample code and/or comments
Import java.sql.*;
The packages used in JDBC are almost always in import?java.sql.*;
Import Oracel or MySQL packages and load drivers in your project:
The classpath of the project and the classpath of the system are put in classpath, if it is placed in the classpath of the system, if the version is different, it may interfere with the different projects in the system, put under the project, reduce the coupling between the project
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.