您的位置:首页 > 编程语言 > Java开发

java命令行编译使用mysql

2012-11-23 16:07 113 查看
javac -classpath ./m.jar:. Test.java

java -classpath ./m.jar:. Test

import java.lang.*;

import java.util.*;

import java.sql.*;

public class Test

{

public static void main( String args[] )

{

Test t = new Test();

t.test();

}

void test()

{

try

{

Class.forName("com.mysql.jdbc.Driver") ;

}catch(ClassNotFoundException e)

{

System.out.println("not find mysql driver, load failed");

e.printStackTrace() ;

}

//String url = "jdbc:hive://localhost:10000/default";

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

String username = "root";

String password = "root";

try

{

Connection con = DriverManager.getConnection(url , username , password ) ;

System.out.println( "connect success" );

}catch(SQLException se)

{

System.out.println("connect failed");

se.printStackTrace() ;

}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: