Java连接mysql数据库源代码
/**
*@author mervyn
*@Development_time 2011.3.12
*@author mervyn
*@Development_time 2011.3.12
*welcome to hi.baidu/mervyn_hb
*/
package src;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.sql.*;
import java.util.*;
*/
package src;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.sql.*;
import java.util.*;
public class MysqlConnectSystem {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws SQLException, IOException {
String Usename,KeyID,UrlString;
//String DriverConnect;
char MenuExitValue;
String driver="sql.jdbc.Driver";
Scanner EntryValue=new Scanner(System.in);
System.out.println("欢迎使用MysqlConnectSystem信息管理系统!");
MysqlConnectSystem mysqlconnect=new MysqlConnectSystem();
MysqlConnectSystem mysqlinsert=new MysqlConnectSystem();
MysqlConnectSystem mysqlupdate=new MysqlConnectSystem();
MysqlConnectSystem mysqldelete=new MysqlConnectSystem();
* @throws IOException
*/
public static void main(String[] args) throws SQLException, IOException {
String Usename,KeyID,UrlString;
//String DriverConnect;
char MenuExitValue;
String driver="sql.jdbc.Driver";
Scanner EntryValue=new Scanner(System.in);
System.out.println("欢迎使用MysqlConnectSystem信息管理系统!");
MysqlConnectSystem mysqlconnect=new MysqlConnectSystem();
MysqlConnectSystem mysqlinsert=new MysqlConnectSystem();
MysqlConnectSystem mysqlupdate=new MysqlConnectSystem();
MysqlConnectSystem mysqldelete=new MysqlConnectSystem();
System.out.println("请输入要登录的用户名:");
();
System.out.println("请输入要登录的数据库的密码:");
();
System.out.println("请输入需要登录的数据库:");
UrlString="jdbc:mysql://127.0.0.1:3306/"+();
do{
try {
Class.forName(driver);
Connection Connection(UrlString, Usename, KeyID);
if(!conn.isClosed())
{
int MenuSelectValue;
System.out.println("Succeeded connectint to the database company!!");
();
System.out.println("请输入要登录的数据库的密码:");
();
System.out.println("请输入需要登录的数据库:");
UrlString="jdbc:mysql://127.0.0.1:3306/"+();
do{
try {
Class.forName(driver);
Connection Connection(UrlString, Usename, KeyID);
if(!conn.isClosed())
{
int MenuSelectValue;
System.out.println("Succeeded connectint to the database company!!");
System.out.println("请选择需要的操作:1、查询数据 2、插入数据 3、更新数据 4、删除数据 ");
Int();
switch (MenuSelectValue){
case 1:
mysqlconnect.Mysql_ConnectExecute_Select(Usename,KeyID,UrlString);
break;
case 2:
mysqlinsert.Mysql_ConnectExecute_Insert(Usename,KeyID,UrlString);
break;
case 3:
mysqlupdate.Mysql_ConnextExecute_Update(Usename,KeyID,UrlString);
break;
case 4:
mysqldelete.Mysql_ConnectExecute_Delete(Usename,KeyID,UrlString);
break;
default:
}
conn.close();
//Statement ateStatement();
}
}catch (ClassNotFoundException e) {
// TODO 自动生成 catch 块
//e.printStackTrace();
System.out.println("不到JDBC驱动模块!");
case 4:
mysqldelete.Mysql_ConnectExecute_Delete(Usename,KeyID,UrlString);
break;
default:
}
conn.close();
//Statement ateStatement();
}
}catch (ClassNotFoundException e) {
// TODO 自动生成 catch 块
//e.printStackTrace();
System.out.println("不到JDBC驱动模块!");
}catch (InputMismatchException e){
System.out.println("输入非法的字符!");
}
System.out.println("是否退出系统? 返回主菜单(java switch case stringm) 退出(e)");
MenuExitValue=(char)ad();
}while(MenuExitValue!='e');
System.out.println("程序已结束!");
}
System.out.println("输入非法的字符!");
}
System.out.println("是否退出系统? 返回主菜单(java switch case stringm) 退出(e)");
MenuExitValue=(char)ad();
}while(MenuExitValue!='e');
System.out.println("程序已结束!");
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论