当前位置: 技术问答>java相关
请教动态建表的问题,代码见内,如果不用变量值就可以建立。但我需要使用变量值.谢谢。
来源: 互联网 发布时间:2015-08-23
本文导语: import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; import java.io.*; import java.sql.*; class oracle implements ActionListener { JTextField name2=null; JTextField name=null; oracle() { JFrame aWindow=new JFrame("Oracle...
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.io.*;
import java.sql.*;
class oracle implements ActionListener
{
JTextField name2=null;
JTextField name=null;
oracle()
{
JFrame aWindow=new JFrame("Oracle testing....");
Toolkit theKit=aWindow.getToolkit();
Dimension wndSize=theKit.getScreenSize();
Container content=aWindow.getContentPane();
aWindow.setBounds(0,0,wndSize.width,wndSize.height);
JPanel panel=new JPanel();
JLabel label=new JLabel("name");
name=new JTextField(10);
JLabel label2=new JLabel("sex");
name2=new JTextField(10);
JButton button1=new JButton("建立");
button1.setFont(new Font("宋体",Font.PLAIN,12));
button1.addActionListener(this);
content.add(panel);
panel.add(label);
panel.add(name);
panel.add(label2);
panel.add(name2);
panel.add(button1);
aWindow.setVisible(true);
aWindow.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
public void actionPerformed(ActionEvent e)
{
String ww=name.getText();
String ee=name2.getText();
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
}catch(ClassNotFoundException oe)
{
System.out.println("ClassNotFoundException:"+oe);
}
try
{
Connection con=DriverManager.getConnection(
"jdbc:oracle:thin:@10.1.7.11:1521:chtf","hailang","willing");
Statement stmt=con.createStatement();
System.out.println(ww);
System.out.println(ee);
ResultSet rs=stmt.executeQuery(
"CREATE TABLE testtest('"+ww+"' varchar2(10) null,'"+ee+"' varchar2(10) null)");
}catch(SQLException oe)
{
System.out.println("SQLException:"+oe);
}
}
public static void main(String[] args)
{
new oracle();
}
}
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.io.*;
import java.sql.*;
class oracle implements ActionListener
{
JTextField name2=null;
JTextField name=null;
oracle()
{
JFrame aWindow=new JFrame("Oracle testing....");
Toolkit theKit=aWindow.getToolkit();
Dimension wndSize=theKit.getScreenSize();
Container content=aWindow.getContentPane();
aWindow.setBounds(0,0,wndSize.width,wndSize.height);
JPanel panel=new JPanel();
JLabel label=new JLabel("name");
name=new JTextField(10);
JLabel label2=new JLabel("sex");
name2=new JTextField(10);
JButton button1=new JButton("建立");
button1.setFont(new Font("宋体",Font.PLAIN,12));
button1.addActionListener(this);
content.add(panel);
panel.add(label);
panel.add(name);
panel.add(label2);
panel.add(name2);
panel.add(button1);
aWindow.setVisible(true);
aWindow.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
public void actionPerformed(ActionEvent e)
{
String ww=name.getText();
String ee=name2.getText();
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
}catch(ClassNotFoundException oe)
{
System.out.println("ClassNotFoundException:"+oe);
}
try
{
Connection con=DriverManager.getConnection(
"jdbc:oracle:thin:@10.1.7.11:1521:chtf","hailang","willing");
Statement stmt=con.createStatement();
System.out.println(ww);
System.out.println(ee);
ResultSet rs=stmt.executeQuery(
"CREATE TABLE testtest('"+ww+"' varchar2(10) null,'"+ee+"' varchar2(10) null)");
}catch(SQLException oe)
{
System.out.println("SQLException:"+oe);
}
}
public static void main(String[] args)
{
new oracle();
}
}
|
"CREATE TABLE testtest('"+ww+"' varchar2(10) null,'"+ee+"' varchar2(10) null)"是这一句吧,好长啊,改成这样
"create table testtest (" +ww+" varchar2(10) null,"+ee+" varchar2(10) null)
顺便问一句,varchar2是oracle的特殊类型吗?
"create table testtest (" +ww+" varchar2(10) null,"+ee+" varchar2(10) null)
顺便问一句,varchar2是oracle的特殊类型吗?