Command statements for Oracle operations in Eclipse

Source: Internet
Author: User
Connectionconthis. creatCon (); get the connection PreparedStatementpstmnull; command Stringsqlquot; insertintostudent (stu

Connection con = this. creatCon (); // get the Connection PreparedStatement pstm = null; // command String SQL = quot; insert into student (stu

Connection con = this. creatCon (); // get the Connection
PreparedStatement pstm = null; // command

String SQL = "insert into student (student_id, name, sex, age) values (?,?,?,?) "; // Set the SQL statement to be executed
Pstm = con. prepareStatement (SQL); // prepare to execute the SQL statement command
Pstm. setString (2, name); // set the value of the 2nd question mark
Pstm. setString (3, sex); // set the value of 3rd question marks
Pstm. setInt (4, age); // set the value of 4th question marks
Pstm. setInt (1, student_id); // set the value of 1st question marks
// Pcmd.exe cuteQuery (); // execute the SQL command. This command returns the ResultSet
Pcmd.exe cuteUpdate (); // run the SQL command to insert, delete, and modify data.
System. out. println ("Write successful"); // whether the write is successful after execution

Connection opening and closing:
// Create a class to connect to the Oracle database
Public static Connection creatCon ()
{
String username = "scott ";
String password = "tiger ";
Connection con = null;
Try
{
Class. forName ("oracle. jdbc. driver. OracleDriver ");
String url = "java: oracle: thin: @ localhost: 1521: ora9i"; // connect to the Oracle database

/* Class. forName ("com. micrsoft. jdbc. sqlserver. SQLServerDriver ");
String url = "java: microsoft: sqlserver: // localhost: 1433"; // connect to the SQL server database */


Con = (Connection) DriverManager. getConnection (url, username, password );
Return con;
}
Catch (Exception exc)
{
System. out. println (exc );
}
Return null;
}
// Close the connection
Public void closeCon (Connection c)
{
Try
{
C. close ();
}
Catch (Exception c1)
{
System. out. println (c1 );
}
}

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.