在正确安装mysql jdbc 有前提下:
import java.sql.*; import java.lang.*; public class ch1 { public static void main(String args[ ]) { String driver ="org.gjt.mm.mysql.Driver"; String url ="jdbc:mysql://127.0.0.1:3306/jsptest"; String user ="hukn"; String password="hukn"; try { Class.forName(driver); } catch(Exception E) { System.out.print("无法加载驱动:"+driver); } try { Connection con=DriverManager.getConnection(url,user,password); if(!con.isClosed()) System.out.println("打开数据库成功"); Statement smt=con.createStatement(); smt.executeUpdate("insert into test(name,adress) values('中国','成都')"); smt.close(); con.close(); } catch(SQLException SE) { System.out.print("打开数据库失败"); } } }
|
[@more@]
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/9650775/viewspace-920826/
,如需转载,请注明出处,否则将追究法律责任。