JDBC
package com.pra.www;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class JDUtil {
//静态代码自动执行
static{
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public Connection getConnection(){
Connection con=null;
String url="jdbc:mysql://localhost:3306/company";
String user="root";
String pwd="root";
try {
con=DriverManager.getConnection(url,user,pwd);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return con;
}
}