com.mysql.jdbc是什么,什么是导入com.mysql.jdbc.Driver;

As part of my project I am trying to connect it with database. I searched in google for the code and I got the following code. In that I don't understand 2 things - "import com.mysql.jdbc.Driver;" and "new Driver". What do these 2 mean ?

package javasql;

import com.mysql.jdbc.Driver;

import java.sql.*;

public class Connect {

public Connect() throws SQLException{

makeConnection();

}

private Connection koneksi;

public Connection makeConnection() throws SQLException {

if (koneksi == null) {

new Driver();

// buat koneksi

koneksi = DriverManager.getConnection(

"jdbc:mysql://localhost:3306/mysql","root","virus");

}

return koneksi;

}

public static void main(String args[]) {

try {

Connect c = new Connect();

System.out.println("Connection established");

}

catch (SQLException e) {

e.printStackTrace();

System.err.println("Connection Failure");

}

}

}

package javasql;

import java.sql.*;

public class SqlStatement {

private Statement statement;

public SqlStatement() throws SQLException{

makeStatement();

}

public Statement makeStatement() throws SQLException{

Connect c = new Connect();

Connection conn = c.makeConnection();

statement = conn.createStatement();

return statement;

}

public void insert(String name,int npm)throws SQLException{

statement.execute("insert into Student values(\""+name+"\","+npm+");");

}

public static void main(String arg[]){

try {

SqlStatement s = new SqlStatement();

s.insert("Ferdi2",3);

s.insert("Anca2",3);

System.out.println("Success");

}

catch(SQLException e){

System.out.println("Failed");

e.printStackTrace();

}

}

}

I use NetBeans IDE to develop my project. When I used these codes I made it as a new project. Then it worked fine. But whenever I tried to include these codes in another projects errors are showing at "import com.mysql.jdbc.Driver;". Why is it so ? Can I use these 2 codes in another projects ?

解决方案

The driver serves as an interface between your application and the database.

Are you using MySQL? If so, you can find the MySQl Java drivers here.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值