I really am new at this, and I don't really know what I'm doing so please be gentle. I have a blueJ program and an SQL database to connect it to. I have a .jar library to connect it but where exactly do I save the library and where exactly is that location stored? here, right?
我真的很陌生,我真的不知道我在做什么,所以请保持温柔。我有一个blueJ程序和一个SQL数据库来连接它。我有一个.jar库来连接它,但我在哪里保存库以及该位置存储的确切位置?在这,对吗?
try
{
String user = "root";
String pass = "12345";
String url = "jdbc:mysql://localhost/mydb";
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection(url, user, pass);
System.out.println ("Database connection established");
}
But in
String url = "jdbc:mysql://localhost/mydb";
String url =“jdbc:mysql:// localhost / mydb”;
The location is different from where I currently have my sql file and jar library stored, so I need to change this line to the location of the file and library? Is that right?
该位置与我目前存储的sql文件和jar库的位置不同,所以我需要将此行更改为文件和库的位置?是对的吗?
To be a numskull here, if I just saved it to the C drive (for the sake of easy understanding) how would I rewrite that line to point there?
要成为一个numskull,如果我只是将它保存到C驱动器(为了便于理解),我将如何重写该行指向那里?
Thanks. Whew.
1 个解决方案
#1
0
import java.sql.*;
public class MysqlConnect{
public static void main(String[] args) {
System.out.println("MySQL Connect Example.");
Connection conn = null;
String url = "jdbc:mysql://localhost:3306/";
String dbName = "jdbctutorial";
String driver = "com.mysql.jdbc.Driver";
String userName = "root";
String password = "root";
try {
Class.forName(driver).newInstance();
conn = DriverManager.getConnection(url+dbName,userName,password);
System.out.println("Connected to the database");
conn.close();
System.out.println("Disconnected from database");
} catch (Exception e) {
e.printStackTrace();
}
}
}
#1
0
import java.sql.*;
public class MysqlConnect{
public static void main(String[] args) {
System.out.println("MySQL Connect Example.");
Connection conn = null;
String url = "jdbc:mysql://localhost:3306/";
String dbName = "jdbctutorial";
String driver = "com.mysql.jdbc.Driver";
String userName = "root";
String password = "root";
try {
Class.forName(driver).newInstance();
conn = DriverManager.getConnection(url+dbName,userName,password);
System.out.println("Connected to the database");
conn.close();
System.out.println("Disconnected from database");
} catch (Exception e) {
e.printStackTrace();
}
}
}