jdbc 如何编写

来源:百度知道 编辑:UC知道 时间:2024/06/20 17:38:28
java与数据库链接的语句如何创建?

加载JDBC驱动,连接数据库:

String url="jdbc:mysql://localhost:3306/jdbc";

String mingzi="root";

String word="123";

String driver="com.mysql.jdbc.Driver";

Connection con=null;

Statement stmt=null;

ResultSet rs=null;

PreparedStatement ps=null;

在main方法中注册驱动程序:

Class.forName(driver);

con=DriverManager.getConnection(url,mingzi,word);

stmt=con.createStatement();

都是一样的,网上有很多,随便搜一下

首先得看你连什么数据库了
如果是Mysql 那么:
String url="jdbc:mysql://localhost:3306/你要连接数据库名字";

String mingzi="root";

String word="123"; //你的数据库密码

String driver="com.mysql.jdbc.Driver";

Connection con=null;

Statement stmt=null;

ResultSet rs=null;

PreparedStatement ps=null;

在main方法中注册驱动程序:

Class