Connect to the database

com.mysql.jdbc.Driver

com.microsoft.sqlserver.jdbc.SQLServerDerver

1. Load the driver Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDerver");

2. Establish a connection

Mysql:    jdbc:mysql://localhost/abc

SQLServer:  String uri = "jdbc:sqlserver"//localhost:1433;databaseName = abc";

DriverManager.getConnection(url,"sa","123");

 

interface:

Statement executes general SQL statements

PreparedStaterment executes precompiled SQL statements

General:

"select * from test where id = " + id both interfaces are acceptable

"select * from test where id = ? " The second   

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325174439&siteId=291194637