如何使用插入Mysql创建Java代码? [英] How Do I Create A Java Code With Insert Mysql?

查看:94
本文介绍了如何使用插入Mysql创建Java代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

{
    
    Connection connect = null;
    Statement statement = null;
    PreparedStatement preSt = null;
    ResultSet resultSet = null;
       
    String url = "jdbc:mysql://localhost:3306/";
		  String dbName = "mydb";
		  String driver = "com.mysql.jdbc.Driver";
		  String userName = "root"; 
		  String password = "promod";
		  try {
		  Class.forName(driver).newInstance();
		  Connection conn = DriverManager.getConnection(url+dbName,userName,password);
		  Statement st = conn.createStatement();
//		  ResultSet res = st.executeQuery("SELECT * FROM mydb");
//		  while (res.next()) {
//		  int id = res.getInt("id");
//		  String msg = res.getString("msg");
//		  System.out.println(id + "\t" + msg);
//		  }
		  int val = st.executeUpdate("INSERT into mydb VALUES("+","+""+")");
		  if(val==1)
			  System.out.print("Successfully inserted value");
		  conn.close();
		  } catch (Exception e) {
		  e.printStackTrace();
		  }







i使用mysql创建了一个数据库

它有id,pass_no,Cntry_Name,Csa_Name,Visa_Name,Sub_Date,Col_Date



Id会自动生成



其他我们必须手动输入到java桌面ui。




i have created a database using mysql
and it has id, pass_no,Cntry_Name, Csa_Name, Visa_Name, Sub_Date, Col_Date

Id will generate automatically

others we have to input manually to java desktop ui.

推荐答案

检查你的数据库名称和表名。你在mysql连接中给出的数据库名称和表名是什么
check your database name and table name. what is the database name and table name that you given into the connection of the mysql


这篇关于如何使用插入Mysql创建Java代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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