package com.company;
/**
* Created by henson on 17-8-31.
*/
import java.sql.*;
public class JdbcTest{
public static void main(String[] args){
try{
Class.forName(
"sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=
DriverManager.getConnection(
"jdbc:odbc:studs",
"",
"");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery(
"select * from stutable");
while(rs.next()){
System.out.println(rs.getString(
"sname"));
}
rs.close();
con.close();
}
catch(Exception e) {
System.out.println(e.getMessage()+
" 666");
}
}
}
package
com.company
import java
.sql.*
public class JDBCDemo {
public static void main(String[] args){
try {
Statement stm
PreparedStatement pstm
ResultSet rs
Class
.forName(
"sun.jdbc.odbc.JdbcOdbcDriver")
String url=
"jdbc:odbc:JDBCDemo"
Connection con=DriverManager
.getConnection(url)
System
.out.println(
"URL:"+url)
System
.out.println(
"Connection:"+con)
stm=con
.createStatement()
System
.out.println(
"DROPTABLE demoTable,if it exists.")
try {
stm
.executeUpdate(
"CREATE TABLE demoTable(" +
"test_id int,tesr_val char(15) not null)")
}catch (Exception e){
System
.out.print(e)
System
.out.println(
"No existing table to delete")
}
System
.out.println(
"table demoTable created!")
stm
.executeUpdate(
"INSERT INTO demoTable("+
"test_id,test_val)VALUES(1,'One')")
stm
.executeUpdate(
"INSERT INTO demoTable("+
"test_id,test_val)VALUES(2,'Two')")
stm
.executeUpdate(
"INSERT INTO demoTable("+
"test_id,test_val)VALUES(3,'Three')")
stm
.executeUpdate(
"INSERT INTO demoTable("+
"test_id,test_val)VALUES(4,'Four')")
stm
.executeUpdate(
"INSERT INTO demoTable("+
"test_id,test_val)VALUES(5,'Five')")
stm=con
.createStatement()
rs=stm
.executeQuery(
"SELECT * from demoTable ORDER BY test_id")
System
.out.println(
"Display all results:")
while (rs
.next()){
int theInt=rs
.getInt(
"test_id")
String str=rs
.getString(
"test_val")
System
.out.println(
"\ttest_id="+theInt+
"\tstr="+str)
}
pstm=con
.prepareStatement(
"UPDATE demoTable SET test_val=? WHERE test_id=?")
pstm
.setString(
1,
"Hello!")
pstm
.setInt(
2,
2)
pstm
.executeUpdate()
System
.out.println(
"Update row number 2:ok.")
stm=con
.createStatement()
rs=stm
.executeQuery(
"SELECT * from demoTable ORDER BY test_id")
System
.out.println(
"Display row 2:")
if (rs
.next() && rs
.next()){
int theInt=rs
.getInt(
"test_id")
String str=rs
.getString(
"test_val")
System
.out.println(
"\ttest_id="+theInt+
"\tstr="+str)
}
con
.close()
}catch (Exception e){
e
.printStackTrace()
}
}
}
package com.company;
public class EvenNum {
public static void main(String[] args){
Runner6 r=
new Runner6();
Timer1 time=
new Timer1();
Thread t1=
new Thread(r);
Thread t2=
new Thread(time);
t1.start();
t2.start();
}
}
class Runner6 implements Runnable {
public void run(){
int i=
1;
while (i<
2000){
if (i%
2==
0)
System.out.println(i);
i++;
}
}
}
class Timer1 implements Runnable{
public void run(){
while (
true) {
System.out.println(
"Hello");
try {
Thread.sleep(
500);
}
catch (InterruptedException e) {
System.out.println(e);
}
}
}
}
package com.company;
import java.io.*;
/**
* Created by henson on 17-8-31.
*/
public class email {
public static void main(String[] args){
try {
FileReader reader=
new FileReader(
"/home/henson/Desktop/110.txt");
BufferedReader br=
new BufferedReader(reader);
FileWriter writer=
new FileWriter(
"email.txt");
BufferedWriter bw=
new BufferedWriter(writer);
String s=br.readLine();
while (s!=
null){
int post=s.indexOf(
"email");
if (post<
0)
return ;
else
s=s.replaceAll(
"email",
"email:");
System.out.println(s);
bw.write(s);
bw.newLine();
s=br.readLine();
}
br.close();
bw.close();
}
catch (IOException e){
System.out.println(e);
}
}
}
突然觉得java越来越有意思了,开心。 只能下载的java1.7怎么还找不到jdbc-odbc桥接驱动。