What is JDBC?
Java is a set of APIs to access databases.
JDBC (Java Database Connectivity) APIs, Java Database programming interfaces, are interfaces and classes in a set of standard Java languages, using these interfaces and classes, java client programs can access different types of databases. For example, you can establish a database connection and execute SQL statements to access data.
The JDBC specification adopts the idea of interface and implementation separation to design the Java database programming framework. Interfaces are included in the java. SQL and javax. SQL packages. java. SQL belongs to JavaSE and javax. SQL belongs to JavaEE. The implementation classes of these interfaces are called database drivers, which are provided by the database vendor or other vendor or individual.
To make the client program independent from a specific database driver, we recommend that developers use an interface-based programming method in the JDBC specification, that is, to make the application only dependent on java. SQL and javax. SQL interfaces and classes.
< strong>
< strong>
< strong>
< strong>
< strong>
< strong>
< strong>
< strong>
< p>
< p>
< p>
< p>
< p>
Class. forName ("oracle. jdbc. oracleDriver "Connection conn = DriverManager. getConnection ("jdbc: oracle: thin :@ localhost: 1521: ORCL", "wladmin", "lan2711" System. out. println ("connection successful" PreparedStatement pStat = conn. prepareStatement ("insert into testresult values (003, 'jdbc ')" System. out. println ("inserted successfully" pStat = conn. prepareStatement ("select * from testresult" ResultSet rs = System. out. println (rs. getInt (1) + "" + rs. getString (2 }}}