Basic database operations using jdbc connection

Source: Internet
Author: User
2, try {Class. forName (driverName); dbConnDriverManager. getConnection (dbURL, userName, userPwd); StatementstdbConn. createStatement (); Create an SQL statement object Stringsgselect * cuteQuery (sg );

2, try {Class. forName (driverName); dbConn = DriverManager. getConnection (dbURL, userName, userPwd); Statement st = dbConn. createStatement (); // create an SQL statement object String sg = select * from Student; // query the Student table ResultSet rs1_st.exe cuteQuery (sg );/

2,

Try {Class. forName (driverName); dbConn = DriverManager. getConnection (dbURL, userName, userPwd); Statement st = dbConn. createStatement (); // create an SQL statement object String sg = "select * from Student"; // query the Student table ResultSet rs1_st.exe cuteQuery (sg); // execute the SQL command, the returned result set is ResultSet while (rs. next () // move the pointer to the next record {System. out. println (rs. getString ("id") + "\ t" + rs. getString ("name") + "\ t" + rs. getString ("phone"); // output query record format} st. close ( ); DbConn. close (); System. out. println ("Connection Successful! 132 "); // If the Connection is Successful, the console outputs Connection Successful! } Catch (Exception e) {e. printStackTrace ();}

2. (1) when executing an SQL statement, use executeQuery (String) to process queries or add records );

(2) Use executeUpdate (String) to process modification or deletion records );


3. When closing, close the Statement class object and then close the connection.

St. close ();

DbConn. close ();

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.