如何使用cmd中的java文件编译mysql JDBC驱动程序 [英] how to compile mysql JDBC driver with a java file in cmd

查看:85
本文介绍了如何使用cmd中的java文件编译mysql JDBC驱动程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用MYsql JDBC Connector编译.java文件

I want to compile .java file with MYsql JDBC Connector

.jar文件所在的位置

This is where the .jar file is

D:\ mysql-connector-java-5.1.31-bin.jar

D:\mysql-connector-java-5.1.31-bin.jar

这是我以前用来编译的...

This is what I used to compile...

javac -cp"D:\ mysql-connector-java-5.1.31-bin.jar" LocationServer.java

javac -cp "D:\mysql-connector-java-5.1.31-bin.jar" LocationServer.java

LocationServer.java的代码

Code for LocationServer.java

import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.ArrayList;

public class LocationServer  {

private static final long serialVersionUID = 1L;
private Connection conn;
private final String driver = "com.mysql.jdbc.Driver";
private boolean connection;

protected LocationServer() {
    try {
        Class.forName(driver);
    } catch (ClassNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    System.out.println("Driver Found");
    location = null;
    x = null;
    y = null;
    conn = null;
    connection = false;
}

public static void main(String[]args){
    LocationServer ls = new LocationServer();
}

当我运行CMD ClassNotFoundException中的代码时,会引发错误.

When I run the the code from CMD ClassNotFoundException throws error.

如何将.jar文件与LocationServer.java正确连接,以便找到MySql Driver类?

How can I properly connect a .jar file with LocationServer.java so that MySql Driver class is found?

推荐答案

如果使用命令提示符,您可以这样做 编译类

Well if you are using command prompt you can do like this Compiling the class

javac LocationServer.java

执行课程

java -cp .;completePathOfMysqlConnector/mysql-connector-java-5.1.6.jar LocationServer

记住它将是;但不是:

这篇关于如何使用cmd中的java文件编译mysql JDBC驱动程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆