Android????MySQL????????????
???????????? ???????[ 2017/3/16 10:37:33 ] ????????????? MySQL Android
???????jdbc?????????£?
????package com.example.mysql;
????import java.sql.Connection;
????import java.sql.DriverManager;
????import java.sql.ResultSet;
????import java.sql.SQLException;
????import java.sql.Statement;
????public class Util
????{
????final static String DRIVER_NAME = "com.mysql.jdbc.Driver";
????public static Connection openConnection(String url?? String user??
????String password)
????{
????Connection conn = null;
????try
????{
????Class.forName(DRIVER_NAME);
????conn = DriverManager.getConnection(url?? user?? password);
????}
????catch(ClassNotFoundException e)
????{
????conn = null;
????}
????catch(SQLException e)
????{
????conn = null;
????}
????System.out.println(conn);
????return conn;
????}
????public static void query(Connection conn?? String sql)
????{
????if (conn == null)
????{
????return;
????}
????Statement statement = null;
????ResultSet result = null;
????try
????{
????statement = conn.createStatement();
????result = statement.executeQuery(sql);
????System.out.println(result);
????if (result != null && result.first())
????{
????int idColumnIndex = result.findColumn("id");
????int nameColumnIndex = result.findColumn("name");
????System.out.println("id " + "name");
????while (!result.isAfterLast())
????{
????System.out.print(result.getString(idColumnIndex) + " ");
????System.out.println(result.getString(nameColumnIndex));
????result.next();
????}
????}
????} catch (SQLException e)
????{
????e.printStackTrace();
????}
????finally
????{
????try
????{
????if (result != null)
????{
????result.close();
????result = null;
????}
????if (statement != null)
????{
????statement.close();
????statement = null;
????}
????}
????catch (SQLException sqle)
????{
????sqle.printStackTrace();
????}
????}
????}
????public static boolean execSQL(Connection conn?? String sql)
????{
????boolean execResult = false;
????if (conn == null)
????{
????return execResult;
????}
????Statement statement = null;
????try
????{
????statement = conn.createStatement();
????if (statement != null)
????{
????execResult = statement.execute(sql);
????}
????}
????catch (SQLException e)
????{
????execResult = false;
????}
????return execResult;
????}
????}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11