myeclip连接Mysql的方法

myeclip连接Mysql的方法
1.新建一个项目
2添加mysql驱动
3新建一个类
 1
 2 import  java.sql. * ;
 3
 4
 5 public   class  test  {
 6
 7    /** *//**
 8     * @param args
 9     */

10    public static void main(String[] args) {
11        // TODO Auto-generated method stub
12        try {
13            new com.mysql.jdbc.Driver();
14            //Class.forName(com.mysql.jdbc.Driver)
15        }
 catch (Exception e) {
16            // TODO Auto-generated catch block
17            e.printStackTrace();
18        }

19        Connection conn=null;
20        Statement stmt=null;
21        ResultSet rs=null;
22        
23        String sql="xxx";
24        
25        try {
26            conn=java.sql.DriverManager.getConnection("jdbc:mysql://localhost:3306/oltest","root","4873617");
27            stmt=conn.createStatement();
28            rs=stmt.executeQuery(sql);
29
30        }
 catch (SQLException e) {
31            // TODO Auto-generated catch block
32            e.printStackTrace();
33        }

34        
35
36    }

37
38}

39


你可能感兴趣的:(myeclip连接Mysql的方法)