java 链接mysql工具包代码
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java 链接mysql工具包代码相关的知识,希望对你有一定的参考价值。
package connutil; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class Connutil { public static Connection Getconn(){ Connection conn = null; try { Class.forName("com.mysql.jdbc.Driver"); conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/homework","root","root"); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return conn; } public static void closeconn(Connection conn,PreparedStatement ps,Statement sta,ResultSet rs){ try { if(conn != null) conn.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { if(ps != null) ps.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { if(sta != null) sta.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { if(rs != null) rs.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
以上是关于java 链接mysql工具包代码的主要内容,如果未能解决你的问题,请参考以下文章
elasticsearch代码片段,及工具类SearchEsUtil.java