Home  >  Article  >  Computer Tutorials  >  Write code using JAVA to create a table

Write code using JAVA to create a table

王林
王林forward
2024-01-24 21:54:12969browse

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!

Statement:
This article is reproduced at:docexcel.net. If there is any infringement, please contact admin@php.cn delete