Alibabacloud.com offers a wide variety of articles about titan graph database java example, easily find your titan graph database java example information here online.
The most basic Oracle database connection code (for oracle11g only):1, right-click Project, build path, configuration build path, select the third item "Library", then click "Add External Jar" and select "D:\Oracle\app\oracle\product\11.2.0\server \jdbc\lib\ Ojdbc6_g.jar "(Note: D:\Oracle is the installation path for the database).2. The following code is a very standard
= "147";//The 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 index of the column name in the tab
Error"); About e.printstacktrace (); $ }
- }
-
- Private StaticConnection connectionget () A {
+Connection conn =NULL;
the Try
- {
$conn =drivermanager.getconnection (URL, user, password); the }
the Catch(SQLException e) the {
theSYSTEM.OUT.PRINTLN ("Database link Error"); - e.printstacktrace (); in }
the returnConn; the }
About
the Private Sta
above objects individually, because if you do not close it, it will affect performance and consume resources $ //Note the order of the closing, the last used first closePanax Notoginseng if(Result! =NULL) - result.close (); the if(Pre! =NULL) + pre.close (); A if(Con! =NULL) the con.close (); +SYSTEM.OUT.PRINTLN ("The database connection is closed! "); - } $ Catch(Exception e) $
");while (Cursor.hasnext ()) {DBObject object = Cursor.next ();System.out.println (Object.get ("name"));// }/*** 7. Check out age is more than 26 years old and English score is less than 80*/DBObject ref = new Basicdbobject ();Ref.put ("Age", New Basicdbobject ("$gte", 26));Ref.put ("E", New Basicdbobject ("$lte", 80));dbcursor cursor = Mongodb.find (ref, NULL, "persons");while (Cursor.hasnext ()) {DBObject object = Cursor.next ();System.out.print (Object.get ("name") + "--");System.out.print (O
In actual development, there may be a need to generate a serial number according to certain rules (for example, according to the company code and date to generate 4-digit serial number) We can combine the company and date as a business code , the value of the business code and sequence stored in the database, Each time you need to generate a serial number of the company and date to generate the business cod
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.