Write code using JAVA to create a table

王林
Release: 2024-01-24 21:54:12
forward
1012 people have browsed it

Write code using JAVA to create a table

How to create a table using JAVA statements

Give you an example:

import java.sql.*;

import java.awt.*;public class Createexp {

public static void main(String args[]){

String url = "jdbc:odbc:wwms"; ///wwms is the data source of ODBC

Connection con = null;

Statement sm = null;try{///Load JDBC-ODBC driver bridge

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

//com.ms.jdbc.odbc.JdbcOdbcDriver /// Wrong, change com.ms to sun

} catch(Exception e){

System.out.println ("Unable to load JDBC-ODBC bridge driver"); return;}/////Establish a connection with the database and display try{con = DriverManager.getConnection(url);

sm = con.createStatement(); //Create object

//Execute the creation operation of database table

sm.execute("create table tb(tepno int, tepname char(10) )");sm.close();

java creates a linear table

import java.util.ArrayList;

import java.util.List;

public class ListDemo {

public static void main(String[] args) {

int numLength = 10;

int deleteNum = 5;

List list = new ArrayList();

init(numLength,list);

delete(deleteNum,list);

print(list);

}

private static void print(List list) {

for(int i=0;i

System.out.print(list.get(i) "\t");

}

}

private static void delete(int deleteNum,List list) {

for (int i=0;i

if((int)list.get(i)==deleteNum){

list.remove(i);

}

}

}

private static void init(int numLength,List list) {

for(int i=1;i

list.add(i);

}

}

}

//Of course it would be better if you post your code. It can help you find the problem. In addition, you can also know how much you know about Java. The help you give may be more practical.

How to add an excel table when developing software with java

HSSFWorkbook wb=new HSSFWorkbook(); //Create an Excel

HSSFSheet sheet=wb.createSheet("sheet1");//Create a Sheet

HSSFRow row=sheet.createRow(0);//Create a row

HSSFCell cell=row.createCell((short)0); //Create a cell

cell.setEncoding(HSSFCell.ENCODING_UTF_16);

cell.setCellValue("serial number"); //Set the value

cell=row.createCell((short)1);

cell.setEncoding(HSSFCell.ENCODING_UTF_16);

cell.setCellValue("surname");

The above is the detailed content of Write code using JAVA to create a table. For more information, please follow other related articles on the PHP Chinese website!

source:docexcel.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template