mysql连接器j_Mysql连接器j错误

我是一个java新手。我正在做一个java上的程序来实现eclipse上的connector j插件。我完成安装后。我测试了数据库连接。下面的代码我用于测试连接。

import javax.swing.JOptionPane;

import java.sql.*;

public class JDBCProgram{

static String userid="root", password = "devkbsc";

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

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

static Statement stmt;

static Connection con;

public static void main(String args[]){

JOptionPane.showMessageDialog(null,"JDBC Programming showing Creation of Table's");

int choice = -1;

do{

choice = getChoice();

if (choice != 0){

getSelected(choice);

}

}

while ( choice != 0);

System.exit(0);

}

public static int getChoice()

{

String choice;

int ch;

choice = JOptionPane.showInputDialog(null,

"1. Create Employees Table\n"+

"2. Create Products Table\n"+

"0. Exit\n\n"+

"Enter your choice");

ch = Integer.parseInt(choice);

return ch;

}

public static void getSelected(int choice){

if(choice==1){

createEmployees();

}

if(choice==2){

createOrders();

}

}

public static Connection getConnection()

{

try {

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); //Class.forName("myDriver.ClassName"); ?

} catch(java.lang.ClassNotFoundException e) {

System.err.print("ClassNotFoundException: ");

System.err.println(e.getMessage());

}

try {

con = DriverManager.getConnection(url,

userid, password);

} catch(SQLException ex) {

System.err.println("SQLException: " + ex.getMessage());

}

return con;

}

/*CREATE TABLE Employees (

Employee_ID INTEGER,

Name VARCHAR(30)

);*/

public static void createEmployees()

{

Connection con = getConnection();

String createString;

createString = "create table Employees (" +

"Employee_ID INTEGER, " +

"Name VARCHAR(30))";

try {

stmt = con.createStatement();

stmt.executeUpdate(createString);

stmt.close();

con.close();

} catch(SQLException ex) {

System.err.println("SQLException: " + ex.getMessage());

}JOptionPane.showMessageDialog(null,"Employees Table Created");

}

/*CREATE TABLE Orders (

Prod_ID INTEGER,

ProductName VARCHAR(20),

Employee_ID INTEGER

);*/

public static void createOrders()

{

Connection con = getConnection();

String createString;

createString = "create table Orders (" +

"Prod_ID INTEGER, " +

"ProductName VARCHAR(20), "+

"Employee_ID INTEGER )";

try {

stmt = con.createStatement();

stmt.executeUpdate(createString);

stmt.close();

con.close();

} catch(SQLException ex) {

System.err.println("SQLException: " + ex.getMessage());

}

JOptionPane.showMessageDialog(null,"Orders Table Created");

}当我执行我发现这在控制台上

ConnectionProperties>

The user to connect as

The password to use when connecting

真的,我不知道我错在哪里。请帮忙

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值