今天进行了android 对mysql数据库的链接。
课上演示加分
import android.util.Log; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class DButil { private final static String driver = "com.mysql.jdbc.Driver"; private final static String url = "jdbc:mysql://10.99.121.119/jiaqi?useUnicode=true&characterEncoding=UTF-8"; private final static String username = "root"; private final static String password = "020907"; Connection conn=null; Statement st=null; ResultSet rs=null; static { try { Class.forName(driver); } catch (ClassNotFoundException e) { System.out.println("加载驱动错误"); } } //2. 获取连接 public static Connection getConnect() throws Exception { return DriverManager.getConnection(url, username, password); } //3. 释放连接资源 public static void release(Connection conn, Statement st, ResultSet rs) throws Exception { if (rs != null) { rs.close(); } if (st != null) { st.close(); } if (conn != null) { conn.close(); } } }
标签:总结,java,每日,3.20,Connection,static,sql,import,null From: https://www.cnblogs.com/syhxx/p/17238280.html