使用java时如何在MySQL中创建表 [英] How to create a table in MySQL when using java

查看:100
本文介绍了使用java时如何在MySQL中创建表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过 java 在 mysql 中创建一个表.顺便说一下,我正在为此使用腻子.这是我到目前为止的一些代码,但它不起作用.

I'm trying to create a table in mysql through java. I'm using putty for this by the way. Here is a bit of the code I have so far but it doesn't work.

rs=s.executeQuery("CREATE TABLE test(id CHAR(2),name VARCHAR(3),PRIMARY KEY(id)); ");
while(rs.next())
{
  System.out.println(rs.getString(1));
}
catch (SQLException ex)
{
  System.out.println("SQLException:"+ ex.getMessage());
}

推荐答案

executeQuery() 用于返回 ResultSet<的查询(通常是 SELECT)/代码>.

对于DML(和DDL)查询,您需要使用executeUpdate() 方法.

With DML (and DDL) queries you need to use executeUpdate() method.

有关更多信息和示例,请使用设置表格教程.

For more information and examples use Setting Up Tables tutorial.

这篇关于使用java时如何在MySQL中创建表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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