This article is a mirror article of machine translation, please click here to jump to the original article.

View: 15542|Reply: 0

[Communication] Java updates database code (adds, deletes, changes), and JDBC updates code

[Copy link]
Posted on 11/18/2014 12:57:53 PM | | | |


[mw_shl_code=java,true]import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;


public class Test {

        /**
         * @param args
         */
        public static void main(String[] args) {
                // TODO Auto-generated method stub
                Set the driver type
                try {
                        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
                        Get a connection object
                        Connection conn=DriverManager.getConnection(
                                        "jdbc:sqlserver://localhost:1433; database=sqlDB; ", "sa", "123");
                        sql statement
                        String sql="insert into userinfo values('2','history','20')";
                        Create an object to execute the command
                        Statement stmt=conn.createStatement();
                        Execute SQL statements
                        stmt.executeUpdate(sql);
                        System.out.println("SQL execution success!");
                       
                } catch (ClassNotFoundException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                } catch (SQLException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }
               

        }

}
[/mw_shl_code]


Database code:

[mw_shl_code=sql,true]create database sqlDB
go
use sqlDB
go

create table userinfo(
        id int primary key,
        qname varchar(10),
        age int
)
go

select * from userinfo[/mw_shl_code]

sqljdbc package: sqljdbc.jar (300.98 KB, Number of downloads: 0, Selling price: 1 Grain MB)




Previous:Apply for Android moderators
Next:Java queries sqlserver database code
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com