Java Keyword Query database

Source: Internet
Author: User

1  PackageCom.ningmeng;2 3 ImportJava.sql.*;4 5  Public classTest07 {6 7      Public Static voidMain (string[] args)throwsException {8Class.forName ("Com.mysql.jdbc.Driver");//Load Database driver9SYSTEM.OUT.PRINTLN ("Load Database driver succeeded");TenString url= "JDBC:MYSQL://LOCALHOST:3306/MLDN";//URL that declares its own database test OneString user= "root";//your own database user name AString pass= "root";//your own database password -             //establish a database connection to get connected objects Conn -Connection conn=drivermanager.getconnection (url,user,pass); theSYSTEM.OUT.PRINTLN ("Connection database driver succeeded"); -Statement stmt=conn.createstatement ();//Create a statement object -String sql= "SELECT * from emp where empno like '%123% '";//Generating SQL statements -ResultSet rs=stmt.executequery (SQL);//Execute SQL statement +              -             intempno; + String ename,job; A java.util.Date hiredate; at             floatSal; -System.out.println ("Empno\t ename\t Job"); -              while(Rs.next ()) { -Empno=rs.getint ("Empno"); -Ename=rs.getstring (2); -Job=rs.getstring ("Job"); inHiredate=rs.getdate (4); -Sal=rs.getfloat (5); toSystem.out.println (empno + "\ T" + ename + "\ T" + Job + +"\ t" +hiredate + "\ T" + sal);//Output Query Results -             } theSYSTEM.OUT.PRINTLN ("Fuzzy query succeeded"); *Conn.close ();//To close a database connection $SYSTEM.OUT.PRINTLN ("Close database connection succeeded");Panax Notoginseng          -          the     } +}

Java Keyword Query database

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.