链接数据库类
package com;
import java.sql.*;
public class Mydb
{
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
public Mydb()
{
try
{
Class.forName("com.mysql.jdbc.Driver");//找驱动对象 找不到报异常
}
catch(Exception e){e.printStackTrace();}
String url="jdbc:mysql://localhost:3306/mydb?useUnicode=true&characterEncoding=gbk";
String user="root";
String password="123456";
try
{
conn=DriverManager.getConnection(url,user,password);
}
catch(SQLException e){e.getMessage();}
}
public ResultSet query(String sql)
{
try
{
stmt=conn.createStatement();
rs=stmt.executeQ
import java.sql.*;
public class Mydb
{
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
public Mydb()
{
try
{
Class.forName("com.mysql.jdbc.Driver");//找驱动对象 找不到报异常
}
catch(Exception e){e.printStackTrace();}
String url="jdbc:mysql://localhost:3306/mydb?useUnicode=true&characterEncoding=gbk";
String user="root";
String password="123456";
try
{
conn=DriverManager.getConnection(url,user,password);
}
catch(SQLException e){e.getMessage();}
}
public ResultSet query(String sql)
{
try
{
stmt=conn.createStatement();
rs=stmt.executeQ