MySQL:
1》下载地址:http://www.mysql.com/products/connector/
2》
//jdbc:[数据库类型]://[ip地址]:[端口号]/[数据库名] private String url = "jdbc:mysql://localhost:3306/userdata"; private String driver = "com.mysql.jdbc.Driver"; private String user = "root"; private String pass = "root123"; try{ Class.forName("com.mysql.jdbc.Driver");//加载驱动 } catch(ClassNotFoundException e){ e.getException(); } //insert into [表名](列名1,列名2) values(?,?) //[]可以省略,()不可以,有几个列就有几个问号 String sql = "insert into userdata.logn(user_logn,user_password) values(?,?) ";//该字符串指出了SQL语句的结构 Connection cnn = DriverManager.getConnection(url,user,pass);//连接数据库 PreparedStatement prep = cnn.prepareStatement(sql);//创建准备好的语句 String a = "asdasdasd",b="123456" ; prep.setString(1,a ); prep.setString(2, b); prep.executeUpdate();//将数据写入数据库,也有可能引发SQL异常 cnn.close();