package com.sx.mas.utils;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class DBConn {
private static final String DRIVER="com.mysql.jdbc.Driver";
private static final String URL="jdbc:mysql://localhost:3306/treedemo";
Connection conn=null;
public Connection getConnection(){
try {
Class.forName(DRIVER);
conn=DriverManager.getConnection(URL,"root","root");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return conn;
}
}
package com.sx.mas.utils;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class DBConn {
private static final String DRIVER="com.mysql.jdbc.Driver";
private static final String URL="jdbc:mysql://localhost:3306/treedemo";
Connection conn=null;
public Connection getConnection(){
try {
Class.forName(DRIVER);
conn=DriverManager.getConnection(URL,"root","root");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return conn;
}
}
第五步:编写javabean类,代码如下,
复制代码 代码如下: