您好,登录后才能下订单哦!
安装mysql
下载 mysql-connector-java-5.1.40-bin.jar驱动包
jdbc.properties
user=root password=1230 driverClass=com.mysql.jdbc.Driver jdbcUrl=jdbc:mysql:///atguigu |
import java.io.IOException; import java.io.InputStream; import java.util.Properties; import java.sql.DriverManager; import java.sql.SQLException;
import com.mysql.jdbc.Connection;
public class JDBCTools {
public JDBCTools() {
}
public static Connection getConnection() throws IOException, SQLException { Connection conn = null; Properties properties = newProperties(); InputStream inStream = JDBCTools.class.getClassLoader() .getResourceAsStream("jdbc.properties"); properties.load(inStream);
String user = properties.getProperty("user"); String password = properties.getProperty("password"); String driverClass = properties.getProperty("driverClass"); String jdbcUrl = properties.getProperty("jdbcUrl");
conn = (Connection) DriverManager.getConnection(jdbcUrl,user,password);
return conn;
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。 |