The body of the

Not to mention, the day basically finished raspberry PI Mysql to go, of course, also read a novel to go… Night to read novels more than eight, began to conceive to my micro mall to join the database to improve, I hope tonight can docking part of the function, when writing this article to insert information, as for how to embed the original mall, let me consider!

The body of the

There’s not much to feel about this time, just a few JDBC details to show:

First point: Java uses SQL statements to pass variables to the database

The complete solution is available on Baidu, so I will post a code directly, surely smart you will know at a glance.

Zhidao.baidu.com/question/87…

 public static void Insert_New_User(String User_Name,String passwd){
            try {
                Class.forName(driver);

                Connection conn = DriverManager.getConnection(url, user, password);

                if(! conn.isClosed()) System.out.println("Succeeded connecting to the Database!");

                Statement statement = conn.createStatement();
                java.util.Date dNow = new java.util.Date();
                SimpleDateFormat ft = new SimpleDateFormat ("yyyy-MM-dd");

                String Rdate=ft.format(dNow);
                String sql = "select id,name,R_date from User";
                String insert = "insert into User(name,password,R_date) values(' "+User_Name+"', '"+passwd+"', '"+Rdate+"')";
    // String delete = "delete from tcount_tbl where runoob_author = \"RUNOOB.COM\" ";
                boolean rs1 = statement.execute(insert);
    // boolean rs1 = statement.execute(delete);
                ResultSet rs = statement.executeQuery(sql);
Copy the code

Mainly is the following, because is passed to the SQL query statement also needs to pass a variable’s value to Mysql, so not only to be separated, but also to add single quotes (what???

String insert = "insert into User(name,password,R_date) values(' "+User_Name+"', '"+passwd+"', '"+Rdate+"')";
Copy the code

If the value is an integer, you don’t need single quotes, but passwd does

User iuser=new User(); iuser.Insert_New_User("ZhangZhaoBo","zzb162122"); ************************************************** Mon Jan 29 22:54:11 CST 2018 WARN: Establishing SSL Connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL Connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification. Succeeded connecting to the Database! -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- the execution result: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ID NAME Register_Date ---------------------------------- 1 ZhangZhaoBo 2018-01-29 2 ZhangZhaoBo 2018-01-29 3 ZhangZhaoBo 2018-01-29 4 ZhangZhaoBo 2018-01-29 ---------------------------------- ----------------------------------Copy the code

Second point: database time entry

The Date is a key in the database, as well as Java attaches great importance to, the Java Data useful, the direct import of Java. Util. * then define the Date object, with Java. But here will produce a SQL. * the Date object of the conflict, So direct global import is good:

                java.util.Date dNow = new java.util.Date();
                SimpleDateFormat ft = new SimpleDateFormat ("yyyy-MM-dd");

                String Rdate=ft.format(dNow);
Copy the code

The other is the time format, very detailed in the following rookie tutorial, I will simply say:

Novice programming -Java date time

If this is the case:

SimpleDateFormat ft = new SimpleDateFormat ("E yyyy.MM.dd 'at' hh:mm:ss a zzz");
Copy the code

This line of code establishes the format of the conversion, where YYYY is the full YEAR, MM is the month, DD is the date, and HH: MM :ss is the hour, minute, and second.

  • Note: there are upper case and lower case formats, such as MM for month and MM for minute; HH is 24 hours and HH is 12 hours.

The compilation and running results of the above examples are as follows:

      System.out.println("Current Date: " + ft.format(dNow));


The Result:

Current Date: Wed 2016.11.09 at 08:23:19 AM UTC
Copy the code

In addition, the rookie tutorial simulator is sent:

Rookie tutorial Java emulator!

There are also a lot of Mysql basic operations, according to some tutorials and web blogs, basic can be all solution! I also speed up to finish, and then to conceive my mall database! Just found it difficult to change the name of the database… I stopped thinking about it… MMP, luckily it’s a play!

Mysql learning (1) Mysql learning (2) Mysql learning (3) Mysql learning (4) Mysql learning (3) Mysql learning (4) Mysql learning (4) Mysql learning (4) Mysql learning (4) Mysql learning (4) Mysql learning (4) [JDBC Tutorial — Ebai Tutorial]

After the body

Slip away slip away. Continue to play database!!